-
-
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 8.0.2 may collect tests multiple times under Windows #12039
Comments
Hi @mrbean-bremen, thanks for the report! Probably it is related to the fix for short paths... perhaps it is collecting the soft-links that Lines 206 to 225 in 98b008f
|
- avoids problem in 8.0.2, see pytest-dev/pytest#12039
@nicoddemus - could be... I have unsucessfully tried to reproduce this locally (using junctions), I may have another look later, maybe tomorrow. |
- avoids problem in 8.0.2, see pytest-dev/pytest#12039
I can confirm that removing the fix for short paths (e.g. the line that uses |
@nicoddemus: I think the test using if sys.platform == "win32" and not is_match:
# In case the file paths do not match,
# account for short-paths on Windows (#11895).
same_file = os.path.samefile(node.path, matchparts[0])
# we don't want to find links or junctions, so we at least
# exclude links/junctions to regular directories
is_match = (
same_file and
os.path.islink(node.path) == os.path.islink(matchparts[0]) and
_is_junction(node.path) == _is_junction(matchparts[0])
) ( Please let me know if this makes sense... |
Hmm it does make sense. Just the |
I wouldn't say that junctions are rare (I use them all the time under Windows, as you need admin rights to create symlinks there), but maybe they are indeed rare for use cases with pytest. I will check tomorrow, if the check for links is sufficient for the CI. |
Ok, I checked. You were right - the problem is indeed solved with the |
Thanks @mrbean-bremen. However I'm having trouble reproducing this in a test, this is what I came up with: import pytest
def test_double_collect_symlinks(tmpdir) -> None:
test_path = tmpdir.join("test_double_collect_symlinks.py")
test_path.write("def test(): pass")
result = pytest.main([str(tmpdir)])
assert result == 0 However this executes just 1 test in several pytest versions I tried:
Can you try to reproduce this problem outside |
I have set up a minimal repository to show this. import pytest
def test_collecting_symlinks(tmpdir):
testname = str(tmpdir.join("first_test.py"))
with open(testname, "w") as fi:
fi.write(
"""
def test_1():
pass
"""
)
args = ["-v", str(tmpdir)]
ret = pytest.main(args, [])
assert ret == 0 and under Linux the output in the CI is as expected:
while under Windows I get:
which is quite a lot of duplication... |
Actually I wrote a test very similar to yours, and it passed locally, but failed in the CI (though with 2 tests passed, not 8, in this case):
|
The check for short paths under Windows via os.path.samefile, introduced in pytest-dev#11936, also found similar tests in symlinked tests in the GH Actions CI. This checks additionally that one of the files is not a symlink. Fixes pytest-dev#12039.
The check for short paths under Windows via os.path.samefile, introduced in pytest-dev#11936, also found similar tests in symlinked tests in the GH Actions CI. This checks additionally that one of the files is not a symlink. Fixes pytest-dev#12039.
The check for short paths under Windows via os.path.samefile, introduced in pytest-dev#11936, also found similar tests in symlinked tests in the GH Actions CI. This checks additionally that one of the files is not a symlink. Fixes pytest-dev#12039.
The check for short paths under Windows via os.path.samefile, introduced in pytest-dev#11936, also found similar tests in symlinked tests in the GH Actions CI. This checks additionally that one of the files is not a symlink. Fixes pytest-dev#12039.
I made a PR for this. |
The check for short paths under Windows via os.path.samefile, introduced in pytest-dev#11936, also found similar tests in symlinked tests in the GH Actions CI. Fixes pytest-dev#12039. Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
I'm not quite sure if this is a bug, or a problem with the test or GitHub Actions, but since version 8.0.2 a test in
pytest-order
fails in the CI under Windows, which worked fine in 8.0.1 and previous versions. Linux and macOS tests are not affected.Pytest run environment in the CI:
The same happens for Python 3.8 - 3.12.
The actual test should collect 6 items (3 tests per test module, in 2 modules) that are created in the directory provided by the
tempdir
fixture,but collects 24 tests in the CI instead. Locally, it works as expected.
Checking the failed tests revealed that the tests have been collected from different locations. The tempdir had been at:
C:\\Users\\runneradmin\\AppData\\Local\\Temp\\pytest-of-runneradmin\\pytest-9\\test_xdist_ordering0
(for a specific run), but the same tests have been discovered with a test ID with just the qualified test name, and additionally with the test IDs:
::::Users::runneradmin::AppData::Local::Temp::pytest-of-runneradmin::pytest-9:::xxx
and::::Documents and Settings::runneradmin::AppData::Local::Temp::pytest-of-runneradmin::pytest-9::xxx
,which are most likely aliases.
I haven't dug into this yet, but I suspect it may have something to do with the fix for the problem with short paths.
The text was updated successfully, but these errors were encountered: