-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
why adding conftest.py "adds" to the sys.path ? #4699
Comments
In short, pytest needs to import the |
Thanks for the fast answer !!! That means than whenever I have a conftest.py file in the uppest level of my project then I can freely make imports in any .py file that I have there and in lower levels ? (No need to "manipulate" the sys.path or stuff like: from ....\xxx import) Relying on the conftest.py (Usually it won't be empty and I will use it for fixture reasons) is it a good "approach" to solve import issues ? |
Exactly, but is not considered a good approach to that problem because it relies on a (necessary) side-effect of how pytest imports It is suggested instead to use virtual environments and "editable" installs. |
Avoid Related: src-based project structures https://hynek.me/articles/testing-packaging/ |
But that could be undone also after importing, couldn't it? |
@blueyed currently, that would break quite some interesting usages (deferred imports in hooks for example) |
@RonnyPfannschmidt It is clear that it would break backward-compatibility (but that's what this issue is about basically). As for deferred imports in hooks, those could also get wrapped by changing sys.path then temporarily I guess. |
@blueyed my feeling is that could generate much more problems than it is worth. |
Hi,
I was having some issues importing a module that is on a folder in an "upper" level than the .py of my test (In general I know that a lot of importing issues in python are related to the sys.path) so I printed the sys.path and effectively I don't see the folder that contains the module that I wanted to import (Despite inside pycharm it gives me autocomplete), however once I create an empty conftest.py in the upper level of my project then I don't have an import error and I can see that having the conftest.py "added" values to the sys.path.
Can someone explain how conftest.py affects the sys.path values ?
Thanks,
David
The text was updated successfully, but these errors were encountered: