-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Suggestion: add new 'parametrization' fixture scope #1552
Copy link
Copy link
Closed
Labels
status: help wanteddevelopers would like help from experts on this topicdevelopers would like help from experts on this topictopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrizetype: backward compatibilitymight present some backward compatibility issues which should be carefully noted in the changelogmight present some backward compatibility issues which should be carefully noted in the changelogtype: enhancementnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branchtype: feature-branchnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branchtype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature
Description
Metadata
Metadata
Assignees
Labels
status: help wanteddevelopers would like help from experts on this topicdevelopers would like help from experts on this topictopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrizetype: backward compatibilitymight present some backward compatibility issues which should be carefully noted in the changelogmight present some backward compatibility issues which should be carefully noted in the changelogtype: enhancementnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branchtype: feature-branchnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branchtype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature
Currently, a fixture can be scoped as function, class, module, or session.
I propose a fixture can also be scoped per parametrization.
Consider:
If I have a group of tests which I am parametrizing, but that would share this value, it'll do the setup for each one (as expected):
If I wanted to run the same group of tests but sharing the fixture, I only really have one option (considering that other tests in the same module need the fixture to be re-set up each time, so I can't use module or session scope): set the fixture scope to class, and put the tests inside a class:
However, the meaning I really intend to convey is "this fixture should be shared across all parametrizations of a function". I propose the following:
This fixture scope conveys, to me: "All parametrizations of this test share the same setup and teardown with regards to this fixture."