-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 on pytest fails when not limiting to the testing folder #3245
Comments
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 main issue is python path overlaps and sys.modules, to me its not clear what other sideeffects the patch you posted wil lhave |
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 in order to keep things safe in general we should have unique folders for all automated tests in some way |
I believe this happened by error rather than someone wanting to run tests in the |
i#d prefer if we includes the documentation folder and actually tested it and the examples there |
Sure, makes sense. |
#3283 added |
By now there's |
it seems our tests fail if we include the documentation folder in a test run
precisely - it makes about 7 tests fail due to path issues
The text was updated successfully, but these errors were encountered: