diff options
Diffstat (limited to 'guide/pytest.html')
-rw-r--r-- | guide/pytest.html | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/guide/pytest.html b/guide/pytest.html index 8e4372a..075231c 100644 --- a/guide/pytest.html +++ b/guide/pytest.html @@ -6,8 +6,8 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" /> <title>pytest recipes — Gentoo Python Guide documentation</title> - <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=4f649999" /> - <link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=039e1c02" /> + <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=d1102ebc" /> + <link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=12dfc556" /> <script src="_static/documentation_options.js?v=5929fcd5"></script> <script src="_static/doctools.js?v=888ff710"></script> <script src="_static/sphinx_highlight.js?v=dc90522c"></script> @@ -18,8 +18,9 @@ <link rel="stylesheet" href="_static/custom.css" type="text/css" /> + + - <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" /> </head><body> @@ -204,6 +205,42 @@ tests up and therefore reduce their flakiness. Sometimes forcing explicit rerun also makes it possible to use xdist on packages that otherwise randomly fail with it.</p> </section> +<section id="using-pytest-timeout-to-prevent-deadlocks-hangs"> +<span id="index-3"></span><h2>Using pytest-timeout to prevent deadlocks (hangs)<a class="headerlink" href="#using-pytest-timeout-to-prevent-deadlocks-hangs" title="Link to this heading">¶</a></h2> +<p><a class="reference external" href="https://pypi.org/project/pytest-timeout/">pytest-timeout</a> plugin adds an option to terminate the test if its +runtime exceeds the specified limit. Some packages decorate specific +tests with timeouts; however, it is also possible to set a baseline +timeout for all tests.</p> +<p>A timeout causes the test run to fail, and therefore using it is +not generally necessary for test suites that are working correctly. +If individual tests are known to suffer from unfixable hangs, it is +preferable to deselect them. However, setting a general timeout is +recommended when a package is particularly fragile, or has suffered +deadlocks in the past. A proactive setting can prevent it from hanging +and blocking arch testing machines.</p> +<p>The plugin can be enabled via setting <code class="docutils literal notranslate"><span class="pre">EPYTEST_TIMEOUT</span></code> to the timeout +in seconds, prior to calling <code class="docutils literal notranslate"><span class="pre">distutils_enable_tests</span></code>. This 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_TIMEOUT</span><span class="o">=</span><span class="m">1800</span> +distutils_enable_tests<span class="w"> </span>pytest +</pre></div> +</div> +<p>The timeout applies to every test separately, i.e. the above example +will cause a single test to time out after 30 minutes. If multiple +tests hang, the total run time will multiply consequently.</p> +<p>When deciding on a timeout value, please take into the consideration +that the tests may be run on a low performance hardware, and on a busy +system, and choose an appropriately high value.</p> +<div class="admonition note"> +<p class="admonition-title">Note</p> +<p><code class="docutils literal notranslate"><span class="pre">EPYTEST_TIMEOUT</span></code> can also be set by user in <code class="docutils literal notranslate"><span class="pre">make.conf</span></code> +or in the calling environment. This can be used as a general +protection against hanging test suites. However, please note that +this does not control dependencies, and therefore the user may need +to install <code class="docutils literal notranslate"><span class="pre">dev-python/pytest-timeout</span></code> explicitly.</p> +</div> +</section> <section id="avoiding-dependencies-on-other-pytest-plugins"> <h2>Avoiding dependencies on other pytest plugins<a class="headerlink" href="#avoiding-dependencies-on-other-pytest-plugins" title="Link to this heading">¶</a></h2> <p>There is a number of pytest plugins that have little value to Gentoo @@ -280,6 +317,23 @@ discovery to the actual test directories, e.g.:</p> </pre></div> </div> </section> +<section id="failures-due-to-missing-files-in-temporary-directories"> +<h2>Failures due to missing files in temporary directories<a class="headerlink" href="#failures-due-to-missing-files-in-temporary-directories" title="Link to this heading">¶</a></h2> +<p>As of 2024-01-05, <code class="docutils literal notranslate"><span class="pre">epytest</span></code> overrides the default temporary directory +retention policy of pytest. By default, directories from successful +tests are removed immediately, and the temporary directories +from the previous test run are replaced by the subsequent test run. +This frequently reduces disk space requirements from test suites, +but it can rarely cause tests to fail.</p> +<p>If you notice test failures combined with indications that a file was +not found, and especially regarding the pytest temporary directories, +try if overriding the retention policy helps, e.g.:</p> +<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_test<span class="o">()</span><span class="w"> </span><span class="o">{</span> +<span class="w"> </span>epytest<span class="w"> </span>-o<span class="w"> </span><span class="nv">tmp_path_retention_policy</span><span class="o">=</span>all +<span class="o">}</span> +</pre></div> +</div> +</section> <section id="fixture-not-found"> <h2>fixture ‘…’ not found<a class="headerlink" href="#fixture-not-found" title="Link to this heading">¶</a></h2> <p>Most of the time, a missing fixture indicates that some pytest plugin @@ -405,9 +459,11 @@ setting ignores <code class="docutils literal notranslate"><span class="pre">Dep <li class="toctree-l2"><a class="reference internal" href="#disabling-plugin-autoloading">Disabling plugin autoloading</a></li> <li class="toctree-l2"><a class="reference internal" href="#using-pytest-xdist-to-run-tests-in-parallel">Using pytest-xdist to run tests in parallel</a></li> <li class="toctree-l2"><a class="reference internal" href="#dealing-with-flaky-tests">Dealing with flaky tests</a></li> +<li class="toctree-l2"><a class="reference internal" href="#using-pytest-timeout-to-prevent-deadlocks-hangs">Using pytest-timeout to prevent deadlocks (hangs)</a></li> <li class="toctree-l2"><a class="reference internal" href="#avoiding-dependencies-on-other-pytest-plugins">Avoiding dependencies on other pytest plugins</a></li> <li class="toctree-l2"><a class="reference internal" href="#typeerror-make-test-flaky-got-an-unexpected-keyword-argument-reruns">TypeError: _make_test_flaky() got an unexpected keyword argument ‘reruns’</a></li> <li class="toctree-l2"><a class="reference internal" href="#importpathmismatcherror">ImportPathMismatchError</a></li> +<li class="toctree-l2"><a class="reference internal" href="#failures-due-to-missing-files-in-temporary-directories">Failures due to missing files in temporary directories</a></li> <li class="toctree-l2"><a class="reference internal" href="#fixture-not-found">fixture ‘…’ not found</a></li> <li class="toctree-l2"><a class="reference internal" href="#warnings">Warnings</a></li> </ul> @@ -454,11 +510,11 @@ setting ignores <code class="docutils literal notranslate"><span class="pre">Dep <div class="clearer"></div> </div> <div class="footer"> - ©2020, Michał Górny, license: CC BY 4.0. + ©2020, Michał Górny, license: CC BY 4.0. | - Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a> - & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a> + Powered by <a href="https://www.sphinx-doc.org/">Sphinx 7.2.6</a> + & <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a> | <a href="_sources/pytest.rst.txt" |