Opt-in FunctionDefinition collection tree node (#3926)#14769
Draft
RonnyPfannschmidt wants to merge 1 commit into
Draft
Opt-in FunctionDefinition collection tree node (#3926)#14769RonnyPfannschmidt wants to merge 1 commit into
RonnyPfannschmidt wants to merge 1 commit into
Conversation
Introduce the ``collect_function_definition`` ini option to promote the internal ``FunctionDefinition`` from a transient parametrization helper to a real collector node in the collection tree. The option is tri-state: - ``hidden`` (default): unchanged flat layout; the definition drives parametrization and is kept out of the tree. - ``pedantic``: insert the definition node between the Module/Class and its test functions; function-level markers are scoped to the definition and each invocation owns only its callspec markers. - ``messy``: migration stopgap -- insert the node but transfer the function-level markers back onto each invocation to preserve the legacy marker layout for code not yet prepared for the new scope; emits a header warning. FunctionDefinition becomes a PyCollector (no longer a Function/Item), so it is collected rather than run. Invocation node ids stay flat and identical across all modes, so selection, caching and reporting are unaffected. obj and instance resolution and getmodpath skip an interposed definition node. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #3926.
Promotes the internal
FunctionDefinitionfrom a transient parametrizationhelper to a real collector node in the collection tree, behind an opt-in ini
option.
collect_function_definition(tri-state string, defaulthidden)hidden(default)Function(legacy)pedanticmessymessyis a migration stopgap for code that is not yet prepared for thedefinition scope — it reproduces the old duplicated-marker layout so bad code
keeps working. The target is
pedantic.What changes
FunctionDefinitionbecomes aPyCollector(no longer aFunction/Item), soit is collected rather than run. Its
collect()runspytest_generate_testsand yields the invocations.
(
test_mod.py::test_x[0]), so-k, caching,--lf, xdist and reporting areunaffected.
obj/instanceresolution andgetmodpathtransparently skip an interposeddefinition node.
iter_markersyields each mark once).The default (
hidden) path is behavior-preserving; the whole test suite passesunchanged.
Known warts / follow-up TODOs
These are intentionally left as follow-ups (inline
TODO(#3926)where relevant),to keep this PR focused — happy to split into a tracking issue:
getfixtureinfoon a collector. The fixture closure must becomputed before the invocations exist, so
FunctionDefinition._generate_functionscalls the item-scoped
getfixtureinfoon the collector via acast. Needs anode-level entry point for closure computation. (
TODO(#3926)inline.)messymode is temporary. It exists only to unblock migration and shouldbe removed once consumers move to the definition scope. Marked clearly in the
docs and header warning.
node and its sole
Functionchild share a node id. Accepted for now; thestructured-nodeids work will give these a better data structure.
originalnamecould now become a read-only property returning thedefinition's name (see the existing note in
Function.__init__).🤖 Generated with Claude Code