-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable fixture dynamic scoping during test run #6101
Comments
How about extracting fixture body into a separate function, and define two fixtures with different scopes that will call the function? def fixture_body():
pass
@pytest.fixture(scope="function")
def some_fixture_module():
fixture_body()
@pytest.fixture()
def some_fixture_function():
fixture_body()
# test_method.py
def test_method(some_fixture_module):
pass
# test_function.py
def test_method(some_fixture_function):
pass |
@rnetser we do have plans to enable fixtures to be available at multiple scopes (i don't have the issue number ready), @aklajnert what you outlined is the current workaround, thanks for taking the time to put it together |
@aklajnert thanks, this is what we have implemented as a workaround. @RonnyPfannschmidt is there a timeline for this? |
@rnetser unfortunately there isn't, when we tried to add the feature for pytest 3.0 in the pytest sprint in Freiburg, we learned that the current conceptual layout of the fixture system makes this feature error prone (@nicoddemus didnt spare efforts to make it work then, however one unexpected bug after another turned up, as such we had to stop and rethink) so far we haven't found the time to find a conceptual layout that makes this feature solid |
@rnetser @nicoddemus now with |
@maricatovictor we didnt touch the relevant fixture internals as of now |
pytest version 5.2.2
Tried to use dynamic scopes for fixtures. However, the scope definition is executed only once - during the fixture definition.
We would like to have option to control fixture scope during test run.
This will allow code re-use in tests which need the code in different scope.
For example: set up a docker - one test needs it in function level and a separate test needs it in module level.
The text was updated successfully, but these errors were encountered: