doc: add example for dynamic session-scoped parametrized fixtures#14320
Open
sedat4ras wants to merge 1 commit intopytest-dev:mainfrom
Open
doc: add example for dynamic session-scoped parametrized fixtures#14320sedat4ras wants to merge 1 commit intopytest-dev:mainfrom
sedat4ras wants to merge 1 commit intopytest-dev:mainfrom
Conversation
Closes pytest-dev#10156 Show how to build a session-scoped parametrized fixture whose params depend on command-line arguments. A plain @pytest.fixture definition cannot do this because params are evaluated at import time, before pytest_configure runs. The solution is to register a plugin class inside pytest_configure, where CLI options are already available. Co-authored-by: Claude <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 #10156
Summary
Adds a documentation example to
doc/en/example/special.rstshowing how to build session-scoped parametrized fixtures whoseparamsdepend on command-line arguments.The problem: A plain
@pytest.fixturedefinition withparamscannot use CLI option values becauseparamsare evaluated at import time — beforepytest_configureruns. This trips up many users (the workaround was buried in a 2017 issue comment).The solution: Register a plugin class containing the fixture inside
pytest_configure, where CLI options are already available.The example was adapted from the working code provided by the issue author in #10156.
Checklist
changelog/10156.doc.rst