Is there a way to control how tests are distributed with pytest --dist loadfile and loadscope

325 Views Asked by At

I am trying to figure out if there is a way I can control/ understand how the tests are distributed between different workers when I use the --dist=loadfile or loadscope feature.

The structure of my project is

tests
     tests_a.py
     .
     .
     .
     .
     .
     tests_h.py

And each test module has a random number of tests defined in it. Let's say I have a particular test in tests_b.py that I want to run at the end of test suite and marked it by using @pytest.mark.last.

I also have the mechanism in that particular test implemented where if it is run by the worker and there are other workers running other tests, it will wait until they all are done. (By using --dashboard function where it updates number of tests are untested)

The problem I am facing is sometimes tests are randomly assigned to different workers and all the other workers complete the tests as expected but the worker working on tests_b.py which has the tearDown()(the function that I want to happen at the very end) runs the test even though there are other modules it needs to complete (lets say tests_f.py is assigned to this same worker). All other workers complete running and close. But this worker runs the tearDown() which waits for all other tests to be completed and is stuck in a loop because the other untested tests are assigned to this same worker and they never get executed. Is there a way to actually make this particular test to run at the end of all the tests that are assigned to the worker?

Thank you

0

There are 0 best solutions below