diff options
Diffstat (limited to 'guide/pytest.html')
-rw-r--r-- | guide/pytest.html | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/guide/pytest.html b/guide/pytest.html index c1446d6..8e4372a 100644 --- a/guide/pytest.html +++ b/guide/pytest.html @@ -154,42 +154,31 @@ look at skip messages and warnings to make sure everything works as intended.</p> </section> <section id="using-pytest-xdist-to-run-tests-in-parallel"> -<h2>Using pytest-xdist to run tests in parallel<a class="headerlink" href="#using-pytest-xdist-to-run-tests-in-parallel" title="Link to this heading">¶</a></h2> +<span id="index-2"></span><h2>Using pytest-xdist to run tests in parallel<a class="headerlink" href="#using-pytest-xdist-to-run-tests-in-parallel" title="Link to this heading">¶</a></h2> <p><a class="reference external" href="https://pypi.org/project/pytest-xdist/">pytest-xdist</a> is a plugin that makes it possible to run multiple tests in parallel. This is especially useful for programs with large test suites that take significant time to run single-threaded.</p> -<p>Not all test suites support pytest-xdist. Particularly, it requires -that the tests are written not to collide one with another. Sometimes, -xdist may also cause instability of individual tests.</p> -<p>When only a few tests are broken or unstable because of pytest-xdist, -it is possible to use it and deselect the problematic tests. It is up -to the maintainer’s discretion to decide whether this is justified.</p> <p>Using pytest-xdist is recommended if the package in question supports it (i.e. it does not cause semi-random test failures) and its test suite -takes significant time. When using pytest-xdist, please respect user’s -make options for the job number, e.g.:</p> -<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>inherit<span class="w"> </span>multiprocessing - -<span class="nv">BDEPEND</span><span class="o">=</span><span class="s2">"</span> -<span class="s2"> test? (</span> -<span class="s2"> dev-python/pytest-xdist[</span><span class="si">${</span><span class="nv">PYTHON_USEDEP</span><span class="si">}</span><span class="s2">]</span> -<span class="s2"> )</span> -<span class="s2">"</span> - +takes significant time. This is done via setting <code class="docutils literal notranslate"><span class="pre">EPYTEST_XDIST</span></code> +to a non-empty value prior to calling <code class="docutils literal notranslate"><span class="pre">distutils_enable_tests</span></code>. +It ensures that an appropriate depedency is added, and that <code class="docutils literal notranslate"><span class="pre">epytest</span></code> +adds necessary command-line options.</p> +<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nv">EPYTEST_XDIST</span><span class="o">=</span><span class="m">1</span> distutils_enable_tests<span class="w"> </span>pytest - -python_test<span class="o">()</span><span class="w"> </span><span class="o">{</span> -<span class="w"> </span>epytest<span class="w"> </span>-n<span class="w"> </span><span class="s2">"</span><span class="k">$(</span>makeopts_jobs<span class="k">)</span><span class="s2">"</span><span class="w"> </span>--dist<span class="o">=</span>worksteal -<span class="o">}</span> </pre></div> </div> <p>Please note that some upstream use pytest-xdist even if there is no real gain from doing so. If the package’s tests take a short time to finish, please avoid the dependency and strip it if necessary.</p> -<p>The <code class="docutils literal notranslate"><span class="pre">--dist=worksteal</span></code> enables rescheduling tests when some of -the workers finish early. It is recommended when some of the package’s -tests are very slow while others are fast. Otherwise, the lengthy tests -may end up being executed on the same thread and become a bottleneck.</p> +<p>Not all test suites support pytest-xdist. Particularly, it requires +that the tests are written not to collide one with another. Sometimes, +xdist may also cause instability of individual tests. In some cases, +it is possible to work around this using the same solution as when +<a class="reference internal" href="#dealing-with-flaky-tests">dealing with flaky tests</a>.</p> +<p>When only a few tests are broken or unstable because of pytest-xdist, +it is possible to use it and deselect the problematic tests. It is up +to the maintainer’s discretion to decide whether this is justified.</p> </section> <section id="dealing-with-flaky-tests"> <h2>Dealing with flaky tests<a class="headerlink" href="#dealing-with-flaky-tests" title="Link to this heading">¶</a></h2> |