title: Could I condition pytest-xdist parallel execution with test dependencies?
body: <p>I was finding out some kind of combination of <em>pytest-xdist</em> with dependency-related plugins like <em>pytest-dependency</em> (but it seems to have some incompatibilities, better to say, <a href="https://github.com/RKrahl/pytest-dependency/issues/8" rel="nofollow noreferrer">they don't get along</a>), or  <em>pytest-ordering</em> with the same <a href="https://github.com/ftobia/pytest-ordering/issues/36#issuecomment-279822189" rel="nofollow noreferrer">problems</a>.</p>
  
  <p>What I need is to <strong>run in parallel but injecting some constraints</strong> 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:</p>
  
  <pre><code>test_suite1 / test_provision.py
              / chapter1 / test_a.py
                           test_b.py
                           ...
              / chapter2 / test_provision.py &lt;= 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
                ...
  ...
  </code></pre>
  
  <p>The idea is to run parallelization respecting the constraints related to dependencies, so, for example, when entering the globbed list of collected tests for <code>test_suite1</code>, pytest-xdist should stop at <code>test_provision.py</code> 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 <code>chapter2 / test_provision.py</code> 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.</p>
  
  <p>If this idea is difficult to carry out, perhaps a simplification could be <strong>mark a test to be executed uniquely when reached</strong> (<em>stopping pytest-xdist</em> 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 <strong>I would prefer to avoid this solution</strong>.</p>
  
  <p>Also, I don't want to run every provision test at the beginning (like <code>pytest -m 'provisions' ; pytest -m 'others'</code>) because some provisions are specializations of upper ones and are incompatible with other branches provision brothers. So, from <em>pytest-xdist</em> point of view, every test, when <em>reached</em> shall acts as it is designed to do.</p>
  
  <p>EDIT: my concern could be understood as a requirement to establish some kind of test affinity towards an specific <em>pytest-xdist</em> worker. This is because If i ensure that some directories are managed by a single worker, I could control the whole picture.</p>