conftest: install the piecewise finder before the translator is imported #2905
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2905
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-conftest-finder-order"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
mainis red on theCIworkflow for one test, and this is why:test_support_installs_the_finder_only_where_the_tokenizer_is_slowasserts which loader the translator was imported through, and under pytest it is always the wrong one.tests/semantic/support.pydoes the right thing — it installsToolsFinderjust beforePathFinderand then importsrdna2spirvthrough it — buttests/conftest.pyimportsrdna2spirvfirst, for its own fixtures:A finder can only take an import it is in
sys.meta_pathfor when the module is first asked for. By the timesupportruns,rdna2spirvis insys.moduleswithPathFinder's loader, andsupport's ownimport rdna2spirvis a no-op.That is also why the same test is green run the other way:
python tests/test_piecewise_parse.pyhas no conftest, sosupportimports first and the finder takes it. Same code, two answers, decided by which runner started it.The change:
conftestputstests/semanticon the path and importssupportbeforerdna2spirv.supportimportsrdna2spirvitself, so the line after it stays and becomes the import that already happened — no fixture changes, no reloads, and nothing that depends on the test's own order.Measured on
main85ec1d33b(CPython 3.14 here, whereneeded()is true):What this does not touch: the finder, the loader,
piecewise_parse, or which Python versions need any of it. It only makes the conftest stop taking the import out from under it.AI-assisted: yes — DeepSeek v4.1 (flash), which ran the test both ways to find out why it disagreed with itself.
Written with an AI assistant.
Independent pytest import-order check at
74da6c8a4+d2a564b66.I ran
python -m pytest -p no:cacheprovider -q tests/test_piecewise_parse.py tests/test_cpu_ref.pyon both revisions. With CPython 3.14.7, main had 64 passes and failed the loader assertion because it usedSourceFileLoader. Main plus this PR passed all 65 tests. Each run also passed 1,870 subtests. With CPython 3.14.10, both revisions passed all 65 tests and 1,870 subtests. Runningpython tests/test_piecewise_parse.pydirectly passed all 26 tests in each of the four runs.MEASURED with synthetic inputs. AI-assisted (Codex).
Both notes taken.
The
sys.dont_write_bytecode = True. You are right that it belongs in the description: importingsupportat conftest time does two things, not one - it putsToolsFinderinsys.meta_pathand it setssys.dont_write_bytecode = True(support.py:55), and the second is a process-wide effect that now happens before any test runs rather than at the first translator import. It is the same setting the semantic tests already ran under, and it stops pytest from dropping__pycache__intotree under test; I have added it to the body rather than leaving it for someone to discover from a stale.pycdirectory.The version range. Fair - the thing that makes it read oddly is that two ranges are involved (3.12 up to before 3.13.16, and 3.14 up to before 3.14.8), so neither
3.13.15nor3.14.7alone is the boundary. The body now says exactly that instead of a shorthand that reads like one range.And the ordering evidence is useful (alone, after
test_wave_diffcollects first, fromtests/as cwd, and with-p no:cacheprovider): that is the shape I could not check from here, because the failure only appears under pytest's conftest.Measured here (CPython 3.14, where
needed()is true):pytest tests/test_piecewise_parse.py26 passed; the same file aspython tests/test_piecewise_parse.pyOK; the five filesci.ymlruns for this area plustest_cpu_ref, 81 passed.Written with an AI assistant.