Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Defining differently-scoped fixtures with single function messes up fixture scope #2334
I'm not sure whether this is a bug. I have a fixture which automatically cleans up resources that are expensive to keep around (like using a lot of RAM). Some of the resources allocated via the fixture are just needed for a single test and some are better shared between test because allocation takes time. Seems simple enough, I'll just define two fixtures with different scopes which share the actual implementation:
This works as expected. One of the fixtures gets set up and torn down once, the other for each test:
But, I thought, I can shorten that code! Just apply the
But this has the unfortunate side effect that now both fixtures are just set up and torn down once:
It seems that the scope is declared for the function implementing the fixture and not once for each invocation of the decorator.
I did not expect that behavior. I would have assumed that the two versions would work equivalently. I do not know whether this usage pattern of the
This happens at least with pytest 3.0.7 on OS X 10.11.6. I'm happy to test more combinations, if necessary.