-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
cannot extend sys.path in conftest.py #3058
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
Comments
Hi @kalidasya, sorry for the delay. I can reproduce the issue but I can't tell right now what might be the problem; I get the error even when I use |
@nicoddemus no worries, thank you for looking into it! |
Hi @kalidasya I had a similar issue before with exactly that KeyError for importing the conftest.py. I fixed it with the following command: |
Thanks @Reinaard, that fixed it for me too:
(... where |
I somehow missed the notifications, will try it again |
still have trouble with it, I will update the ticket when I figured out something new. I delete all pyc file, also changed from socketsever to ssh, also added the test files in the container and not mount them |
Hi,
system and software info:
centos
7.2python
3.6.3pytest
3.3.1I am facing an issue when I try to manipulate
sys.path
inconftest.py
(conftest file in project root). It seems it does not have an effect and related imports will fail afterwards. Moving the conftest into the test folder works the same.I have the following structure:
The project itself is an integration test framework so it is not the system under test, the
src
folder contains util functions.I run the test with
py.test scripts2/test.py -s
from rootThe content of
test.py
:content of
conftest.py
:content of
util.py
:if I have the conftest.py and run the pytest command I get the following error:
if I remove conftest.py and enable the sys.path manipulation in the test itself, it works. I cannot use this workaround as my real test framework is more complex and there are many tests in it. I also tried a baked dynamic import with
importlibs
that seems to work to a certain extend but some test files will still fail to import things (I tried only in the real complex project):For this simple example this solves the problem:
The bigger picture. I discovered this issue while I was working on an xdist + docker setup where the docker container has the socket server implementation of
execnet
. I kept getting this error even if thepyexecnetcache
had the correct data in the container. I was able to import things viaimp
orimportlib
, so I was sure its not related to missing files or file rights. I started to narrow down the problem as I was not sure ifexecnet
orxdist
orpytest
is the root cause, and this is how I ended up with the smallest/simplest reproduction of the problem.The text was updated successfully, but these errors were encountered: