Skip to content

Instantly share code, notes, and snippets.

@RonnyPfannschmidt
Created August 8, 2018 19:10
Show Gist options
  • Save RonnyPfannschmidt/494417c9f4ef14362d512e54943890d1 to your computer and use it in GitHub Desktop.
Save RonnyPfannschmidt/494417c9f4ef14362d512e54943890d1 to your computer and use it in GitHub Desktop.
the parametersets of the different fixtures create a dependency tree,
so the test using only foo gets executed 3 times,
the test using bar gets executed 9 times
and the test using baz gets executed 27 times
simply generating the runs in order of the tests would mean that for each test all fxtures of all scopes would have to be set up and tear down
so foo would setup 39 times instead of 3 times
pytest does something to reorder the 39 tests after it generated them to limit the setup/teardown actions based on shared bits of that topology
what i want to do is take the topology of the fixtures and their parameters, and the list of tests and what they need, and generate a list of actions to set up/tear down those fixtures and run the actual tests
# not run, jsut to show the structure
@pytest.fixture(params=[1,2,3], scope="session")
def foo(request):
return request.param
@pytest.fixture(params=list("abc"), scope="module")
def bar(request, foo):
return request.param
@pytest.fixture(params=list(",.-"), scope="function")
def baz(request, bar):
return request.param
def test_b(bar):
pass
def test_a(foo):
pass
def test_c(baz):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment