Skip to content

Cache directory collection when multiple file args share a parent - #15194

Open
Eryx-Z wants to merge 3 commits into
pytest-dev:mainfrom
Eryx-Z:fix/15187-cache-directory-collection-for-file-args
Open

Eryx-Z wants to merge 3 commits into
pytest-dev:mainfrom
Eryx-Z:fix/15187-cache-directory-collection-for-file-args

Conversation

@Eryx-Z

@Eryx-Z Eryx-Z commented Oct 16, 2026

Copy link
Copy Markdown

Summary

When several test files from the same directory are passed as separate command-line arguments, Session.collect re-collected the parent directory once per argument, making collection cost O(files × directory entries).

Use the collection cache for Directory nodes in that branch (unless --keep-duplicates is set). File-level non-deduplication for a path named twice remains handled in genitems.

Fixes #15187.

Test plan

  • New regression test: five file args from one directory each offered to pytest_collect_file once
  • Manual check: three file args report one collect_file call each; --keep-duplicates with a repeated file still collects twice

Eryx-Z and others added 3 commits October 17, 2026 07:57
Session.collect disabled the collection cache for a file's parent
Directory whenever the remaining match part was a single file path.
That made N explicit file arguments from the same directory re-walk
the directory N times (quadratic in directory size).

Keep using the cache for Directory nodes unless --keep-duplicates is
set; file-level non-dedup is already handled in genitems.

Fixes pytest-dev#15187.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collection is quadratic in the number of file arguments from one directory: each file argument re-collects its parent directory

1 participant