pytest-repeat
pytest-repeat copied to clipboard
Test fixture executes only once when fixture scope is 'module' and 'count' > 1
Hello,
Many thanks for this useful plugin. I'm confused a bit. When I create test fixture whit scope 'module' I expect fixture code to be executed 'count' times but it does only first time. May be this should not be default behavior but it seems to be very useful feature.
unfortunately this is the default behaviour as per implementation - the fixture implementing the behaviour is function scoped
it may be sensible to make the scope of the fixture configurable
@RonnyPfannschmidt - I have a similar use-case. I'd like my 'repeat' runs to essentially handle the fixture code new each time. You mention the fixture code as only executing once as the default - does that mean executing it multiple times exists somewhere?
My Use Case - each test file/module/class in my code has a setup fixture which creates an isolated environment. At the end of the run, I wipe it out. My hope was that a file/module/class scoped repeat run would setup/teardown class fixtures the exact same if I had only run it once. So if I ran this with xdist n=10 and pytest-repeat count=10, each xdist worker would create a unique environment and run it once. If I ran with xdist n=10 and pytest-repeat count=20, I'd expect each worker to (1) uniquely set up an environment, (2) execute tests, (3) teardown, and (4) repeat steps 1-3.
its a function scope fixture with a parameter, so it cant affect teardown at other levels
So there is no possibility to run module fixture again on every module repetition? even for the session scope repetition... I have tests in modules, every module has a fixture for preparing environment for tests in this module and fixture need to be used before repetition.
Currently not
Thank you for quick response :) So it will not fit for my test environment, but it is cool plugin anyway! Maybe in the next project.
It's unfortunate the scope is not configurable yet, but fixable by dynamic creation of the fixture
If there's more than one test module, and --repeat-scope=session, then the module scope fixtures run each time for each module, as expected. I think this can be closed, or changed to a feature request with a new flag, as changing current behavior to the requested behavior of this issue would break some people