-
-
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
Pytest adds parent instead of expected directory into python path. (shouldn't it add rootdir?) #2589
Comments
Hi @cepbrian thanks for writing. A quick look at the code indicates that pytest first looks for I might be missing something (it is late and I should be in bed by now), but can you provide an example where pytest ignores |
Looking at this more carefully, the problem ISN'T rootdir. The problem is that rootdir isn't what's put into pythonpath. |
Hmm
given that |
The question is how is rootdir used? shouldn't that be the thing that is put into pythonpath? If not, then there should be some more documentation somewhere about how pytest determines its pythonpath, because it's doing something weird... |
Pytest is clearly adding the work directory, because when I run with python -m pytest, I get:
python adds '' as normal. and then pytest adds /Users/brianp/work... |
OK that's a problem people often run into. I updated the title of the issue to better reflect that. The
That happens because your test is in a package (in the same directory as an This is how pytest deals with the problem of importing test files which are part of a package, and is not really related to |
ok. I guess my point was just when looking for "how does pytest figure out what to put into python path" the only thing I found in the documentation was "rootdir", which didn't make clear that it WASN'T what was added to python path, nor did anything make clear what WAS. Like I said initially, this is likely just a documentation issue. There should be an easily found documentation on "what does pytest do with pythonpath?" I assumed that "rootdir" was used for pythonpath, because nothing else seemed to be, and it seemed reasonable... Again, a documentation issue. |
I see, the confusion is understandable; like I said this is a common source of confusion among users. Noted about how to improve that on the docs, that's an area where we definitely need improvement! I guess there are two points that deserve some better docs:
What do you think? |
yes! thanks! |
- Also minor adjustments in the docs (wording, formatting, links, etc). Fix pytest-dev#2589
- Also minor adjustments in the docs (wording, formatting, links, etc). Fix pytest-dev#2589
Using pytest 3.1.3, python 2.7, OSX 10.12.5
Looking at https://docs.pytest.org/en/latest/customize.html Which appears to be the most recent documentation.
Documentation says that it looks for pytest.ini to find rootdir. Instead it looks up from tests dir until it finds a dir without init.py.
I'm not sure if this is a documentation error, a linking error in the docs (It's not pointing to the most recent version of the docs somehow) or an actual error in the code. I'm guessing it's just that the docs aren't up to date, but that's just a guess.
EDIT:
It appears that I asked the wrong question. (leaving it there for clarity)
The question isn't actually about rootdir. The issue is that the documentation doesn't clearly say what pytest puts in PYTHONPATH. As such, I assumed it put rootdir. And so I assumed it was not setting rootdir correctly. It turns out that it is setting rootdir just fine, but it doesn't use rootdir in pythonpath at all.
I believe that there should be some (perhaps just some easier to find) documentation on how pytest sets pythonpath.
The text was updated successfully, but these errors were encountered: