1

I was finding out some kind of combination of pytest-xdist with dependency-related plugins like pytest-dependency (but it seems to have some incompatibilities, better to say, they don't get along), or pytest-ordering with the same problems.

What I need is to run in parallel but injecting some constraints to guarantee that some tests related to common tasks (mainly database provision for specific tests) are executed isolated prior the rest of tests of a 'parallelization' group. For example, I would like to organize my tests something like this:

test_suite1 / test_provision.py
            / chapter1 / test_a.py
                         test_b.py
                         ...
            / chapter2 / test_provision.py <= don't pay attention on test names issues (this
                         test_a.py            can be named  test_suite1_chapter2_provision.py
                         test_b.py            or __init__.py can be used to avoid the problem
                         test_c.py            of unique names)
                         ...
              ...
test_suite2 / test_suite2_provision.py
              ...
...

The idea is to run parallelization respecting the constraints related to dependencies, so, for example, when entering the globbed list of collected tests for test_suite1, pytest-xdist should stop at test_provision.py running it serially, then run chapters in parallel and so on. Some chapters could have also constraints (i.e. chapter2 test_provision.py) and this shall be also respected: first provision, then chapter2 child tests ... In the example chapter2 / test_provision.py is in the same directory as tests, this is not a matter of filesystem hierarchy organization (although this is probably a project agreement and probably should be uniform: for example, provision tests isolated on parent directories or something like this). Thus, I expect to insert pytest marks or similar to create dependencies at tests definitions, not at filesystem.

If this idea is difficult to carry out, perhaps a simplification could be mark a test to be executed uniquely when reached (stopping pytest-xdist parallel execution for the whole bunch of collected tests), then, although others could indeed be parallelized with it we could sacrify this for a greater good which is avoid collisions in the test plan (and thus, avoid failed executions). But this would imply greater total execution time and I would prefer to avoid this solution.

Also, I don't want to run every provision test at the beginning (like pytest -m 'provisions' ; pytest -m 'others') because some provisions are specializations of upper ones and are incompatible with other branches provision brothers. So, from pytest-xdist point of view, every test, when reached shall acts as it is designed to do.

EDIT: my concern could be understood as a requirement to establish some kind of test affinity towards an specific pytest-xdist worker. This is because If i ensure that some directories are managed by a single worker, I could control the whole picture.

eramos
  • 196
  • 1
  • 16
  • You would need to write your own scheduler; check out https://stackoverflow.com/q/59498774/2650249 for an example. – hoefling May 15 '20 at 18:16
  • Ok, thank u for the link. I understand that in that example, MyScheduler groups those under `test/functional/` to be the same module, and, as that inherits from loadscope this means they run in the same worker: sequentially. But in my case, I think I would need them parallel, but depending on some upper tests in the file hierarchy.So, that group and the group with provisions (normally 1 provision test), are sequential themselves, but parallel within them. Could a user-defined scheduler reach that objective ? – eramos May 15 '20 at 22:49

0 Answers0