pytest-repeat icon indicating copy to clipboard operation
pytest-repeat copied to clipboard

Test fixture executes only once when fixture scope is 'module' and 'count' > 1

Open vukis opened this issue 7 years ago • 7 comments

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.

vukis avatar Feb 09 '18 10:02 vukis

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 avatar Feb 15 '18 09:02 RonnyPfannschmidt

@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.

markabrezovec-eaton avatar Nov 25 '19 20:11 markabrezovec-eaton

its a function scope fixture with a parameter, so it cant affect teardown at other levels

RonnyPfannschmidt avatar Nov 25 '19 22:11 RonnyPfannschmidt

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.

DadroIT avatar May 20 '20 11:05 DadroIT

Currently not

RonnyPfannschmidt avatar May 21 '20 08:05 RonnyPfannschmidt

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.

DadroIT avatar May 21 '20 08:05 DadroIT

It's unfortunate the scope is not configurable yet, but fixable by dynamic creation of the fixture

RonnyPfannschmidt avatar May 21 '20 09:05 RonnyPfannschmidt

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

okken avatar Jan 02 '24 21:01 okken