Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py.test --doctest-modules fails if python setup.py build has been run. #539

Closed
pytestbot opened this issue Jul 13, 2014 · 10 comments
Closed
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Tom Prince (BitBucket: tomprince, GitHub: tomprince)


py.test will recurse into the distutils build directory looking for modules to run doc-tests for, but will try to import them from the root directory, leading to a mismatch between files:

________________________________________________________ ERROR collecting service_identity/_common.py _________________________________________________________
../../dev/tmp-111d346bc44a488b/lib/python2.7/site-packages/py/_path/local.py:639: in pyimport
>               raise self.ImportMismatchError(modname, modfile, self)
E               ImportMismatchError: ('service_identity._common', '/Users/cougar/src/service_identity/build/lib/service_identity/_common.py', local('/Users/cougar/src/service_identity/service_identity/_common.py'))

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@reubano
Copy link

reubano commented Jul 1, 2016

What's the status on this issue?

@RonnyPfannschmidt
Copy link
Member

so far it hasn't been changed, one should use the testdirs ini setting instead

@reubano
Copy link

reubano commented Jul 4, 2016

@RonnyPfannschmidt what do I put exactly? I didn't see a testdirs option in the docs. This is my setup.cfg:

[pytest]
addopts=--doctest-modules
testpaths=bin tests examples riko
norecursedirs=lib include .tox

@nicoddemus
Copy link
Member

nicoddemus commented Jul 5, 2016

@reubano, @RonnyPfannschmidt probably meant testpaths. Are you having the same problem, even with the setup.cfg above?

@reubano
Copy link

reubano commented Jul 5, 2016

Yes, this setup doesn't work.

@nicoddemus
Copy link
Member

@reubano sorry for not getting back to this sooner.

Could you please post your full terminal output?

@asottile asottile changed the title py.test --doctest-modules fails if python setup.py buld has been run. py.test --doctest-modules fails if python setup.py build has been run. Jul 7, 2018
@Erotemic
Copy link

This behavior also occurs for xdoctest (my extended doctest plugin). I see the behavior if I run python setup.py install (instead of python setup.py develop, which works) and then pytest. The regular unittests work fine, but when it parses the doctest it parses them from the source folder instead of the folder that was installed. Thus I get an error like:

E           _pytest.nodes.Collector.CollectError: import file mismatch:
E           imported module 'xdoctest.utils.util_stream' has this __file__ attribute:
E             /home/joncrall/.local/conda/envs/py36/lib/python3.6/site-packages/xdoctest-0.5.9-py3.6.egg/xdoctest/utils/util_stream.py
E           which is not the same as the test file we want to collect:
E             /home/joncrall/code/xdoctest/xdoctest/utils/util_stream.py
E           HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

The behavior is the same with the builtin doctest plugin, so its not just an issue with xdoctest.

The reason I tested this way instead of doing an in-source build and testing was because there was an issue that only occurred when my package was installed (running it from the source tree was not a problem).

@graingert
Copy link
Member

@nicoddemus
Copy link
Member

@graingert thanks, updated the link in the original post: https://docs.pytest.org/en/latest/reference.html#confval-testpaths

@nicoddemus
Copy link
Member

Btw, I have just tried the original issue (doctest modules in the build folder) and it has been fixed since we have updated the default norecursedirs option to include build by default.

I'm closing this issue then, if others have similar problems let's post them here and/or open a new issue if it's a different problem. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

6 participants