-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[WIP] Track visited files and directories when collecting #4203
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function | ||
import sys | ||
|
||
import six | ||
|
||
import py | ||
import pytest | ||
|
||
|
||
@pytest.mark.skipif( | ||
not hasattr(py.path.local, "mksymlinkto"), | ||
reason="symlink not available on this platform", | ||
) | ||
def test_624(testdir): | ||
""" | ||
Runs tests in the following directory tree: | ||
|
||
testdir/ | ||
test_noop.py | ||
symlink-0 -> . | ||
symlink-1 -> . | ||
|
||
On Linux, the maximum number of symlinks in a path is 40, after which ELOOP | ||
is returned when trying to read the path. This means that if we walk the | ||
directory tree naively, following symlinks, naively, this will attempt to | ||
visit test_noop.py via 2 ** 41 paths: | ||
|
||
testdir/symlink-0/test_noop.py | ||
testdir/symlink-1/test_noop.py | ||
testdir/symlink-0/symlink-0/test_noop.py | ||
testdir/symlink-0/symlink-1/test_noop.py | ||
.. and eventually .. | ||
testdir/symlink-0/.. 2 ** 39 more combinations ../test_noop.py | ||
testdir/symlink-1/.. 2 ** 39 more combinations ../test_noop.py | ||
|
||
Instead, we should stop recursing when we reach a directory we've seen | ||
before. In this test, this means visiting the test once at the root, and | ||
once via a symlink, then stopping. | ||
""" | ||
|
||
test_noop_py = testdir.makepyfile(test_noop="def test_noop():\n pass") | ||
|
||
# dummy check that we can actually create symlinks: on Windows `py.path.mksymlinkto` is | ||
# available, but normal users require special admin privileges to create symlinks. | ||
if sys.platform == "win32": | ||
try: | ||
(testdir.tmpdir / ".dummy").mksymlinkto(test_noop_py) | ||
except OSError as e: | ||
pytest.skip(six.text_type(e.args[0])) | ||
|
||
for i in range(2): | ||
(testdir.tmpdir / "symlink-{}".format(i)).mksymlinkto(testdir.tmpdir) | ||
|
||
result = testdir.runpytest() | ||
result.assert_outcomes(passed=2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@boxed will not like that.. ;)
You might be interested in #4237 and the discussion at #2206.
There is also
_recurse
in the python plugin.I've also added
seen_dirs
in #4237, and wonder if a combination ofrealpath
and this would be better maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think
stat()
(a single syscall) is costly, why wouldrealpath()
be any better? (Its implementation is, roughly, split the path on the path separator, and callos.lstat()
on each component.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather annoyingly,
os.DirEntry
(yielded byos.scandir()
) includes the inode number but not the device number.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a joke I think. I have been trying to cut down on stat() calls because pytest has made millions of them in some rather simple test scenarios. A single stat() call here and there won't be a big deal. The problem is that there has been very many "just a single" things in pytest from 3.4 to 3.9 and some of those weren't really "single" because they were used in a loop (in a loop!).
So I don't know about this case, but you could try running my test script #2206 (comment) and see if performance is impacted significantly or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was joking.
But I also think that since we're doing
realpath
already for symlink-resolving it might not be necessary to do anystat
anymore on top.I think this should be rebased on features, and then maybe only small changes are required to make the test pass.