Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
py.test on pytest fails when not limiting to the testing folder #3245
I just looked into this a bit, and the test failure is occuring on tests that use tempdirs named "sub1" and/or "sub2".
The root issue appears to be from doc/en/example/costlysetup.
For some reason, this will then cause all test functions that then go on to call
I tried poking around in _pytest/config.py to find out why this exception was being raised, but couldn't figure out why it's only raised after the costlysetup test is run.
@jeffreyrack great job with the investigation, basically costlysetup gets added to pythonpath, and later tests are unable to find the module in any sane way since theirs looks the same, if there is also conftests around, then this also mismatches
this is in part a shortcoming of pytester and in part of our own setup layout
Interestingly enough, the issue seems to be that py.path is trying to import sub1.conftest, which it's unable to find in the path.
For example, in this test that currently fails in metafunc.py, if I add logic to remove init.py, then it will pass:
The reason is that after costlysetup is run, py.path will try to do:
It's still not clear to me why costlysetup messes with this at all, as I don't see anything in costlysetup that messes with the path.
The issue is that when pytest initially loads the tests, it imports the doc/en/example/costlysetup/sub1 module as sub1.
Then, when the tests later on get ran that also create a sub1 module, import sub-modules fails because the import (in this case above, it ends up calling
Given the above, the reason that removing __init__.py works is because then pyimport won't perceive the conftest.py file as being part of a python package. So, instead we essentially do
I think the best way to solve this would be to fix the directory layout issue, and have the costlysetup example use sub-directory names other than sub1 and sub2 as those package names are assumed to be unused by our automated tests.
Maybe renaming them to sub_a and sub_b?
I believe this happened by error rather than someone wanting to run tests in the