-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
rootdir for pytester identified as /tmp when passing a tmpfile in /tmp as part of a argument #11781
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
rootdir is identified as /tmp - something went deep wrong - most likely related to using named temporary files instead of the testdir since the metadata file is in /tmp, the folder finding gets confused it seems |
Right to add o what @RonnyPfannschmidt said, this is a combination of two things: Problempytest bootstrapping:pytest uses an elaborate procedure to decide what to use for the The comic part is that this has to happen before plugins are loaded. So if the invocation is This is a pretty silly but it's how it is now. Changes in pytest 8:The above has always been true so why does it start failing with pytest 8? The reason is that PR #11646 has made pytest scan the rootdir a bit more due to larger reliance on the " Workarounds
Possible solutions in pytest
|
I've implemented workaround number 3. Probably good hygiene to keep any created files in the temporary test directory anyway. Let me know if there's anything I can help with. |
Collection should be limited to the invocations directory in the case we hit here |
Work around the pytest issue pytest-dev/pytest#11781 by replacing `pytest rootdir=./tmp -v` with `pytest rootdir=. -v` Co-authored-by: ThreeMonth03 <[email protected]>
Work around the pytest issue pytest-dev/pytest#11781 by replacing `pytest rootdir=./tmp -v` with `pytest rootdir=. -v` Co-authored-by: ThreeMonth03 <[email protected]>
Something about this change in rootdir behaviour has broken the test suites in at least I copied the two scripts from https://github.com/pytest-dev/pytest-order/blob/main/tests/test_xdist_handling.py into two files in
as does
and
All of these set However the following test fails:
Now I followed the stated algorithm at https://docs.pytest.org/en/8.0.x/reference/customize.html#finding-the-rootdir manually, and none of the criteria for making The following also doesn't work; it seems that
A workaround is to touch a file I had a look at the code in pytest/src/_pytest/config/findpaths.py Line 172 in 12e061e
|
I am not sure why the rootdir ends up as The permission error though is a known issue since pytest 8 that is quite hard to fix but it's certainly on the radar.
This one is expected, you are collecting |
Hi @bluetech, thanks for your detailed comments!
Yes, that's what I saw, and I also don't understand it. It's certainly not what is described in the documentation, and it seems to possibly be undesirable behaviour. There are quite possibly arguments for doing this, but it is not described as a breaking change in the Changelog (or even mentioned, for that matter). In version 7.4.4, this line of code read: pytest/src/_pytest/config/findpaths.py Line 183 in 33f694f
The source of the change was two months ago: I've now checked these same tests with pytest 7.4.4, and discovered that they all pass, so this really is a change of behaviour. (And despite having the line pytest/src/_pytest/config/findpaths.py Line 198 in 33f694f
in version 7.4.4, somehow the rootdir is correctly set even when pytest is invoked from /tmp .)
The permission error is only triggered in this case because of the rootdir issue.
I don't understand why it fails, though; the documentation says:
EDIT: I was wrong about 7.4.4:
So the rootdir is still Maybe the rootdir is wrong in both cases? |
Actually, I'm not sure if that patch is the cause now; |
Ah, figured out the comment about
|
Here's a suggestion: change pytest/src/_pytest/config/findpaths.py Lines 210 to 215 in 12e061e
to simply read: if rootdir is None:
rootdir = ancestor The reasoning is this: if pytest is called as Making this change causes several tests to fail, though:
Hmmm. So lots would possibly break with this change. I don't know what the best resolution is; perhaps expect all people calling pytest within tests to explicitly state their rootdir on the command line if that is appropriate? |
- fixes #110 - related to pytest-dev/pytest#11781
pip list
from the virtual environment you are usingPlease feel free to edit the title 😅
This PR made some of my tests start to fail with
PermissionError: [Errno 13] Permission denied: '/tmp/snap-private-tmp/__init__.py'
https://github.com/pytest-dev/pytest-metadata/actions/runs/7365057317/job/20046008077
The tests pass against c7ee5599, but fail on this merge.
Running it locally I also get some warnings:
warnings
I tried to figure out exactly where it goes wrong, but failed. It's entirely possible there's something wrong in my plugin that was just surfaced by the changes in this PR.
Please let me know what information I can contribute with.
pip list
I've tried the code on python 3.9...3.13 and it fails on all of them.
CI is Linux
Locally I'm on a Mac
The text was updated successfully, but these errors were encountered: