summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2023-01-14 16:37:27 +0100
committerMichał Górny <mgorny@gentoo.org>2023-01-14 16:37:27 +0100
commitc01c3cbddc8ea0575bbea41b644f14704fff7741 (patch)
tree75bd71fd23bbf4ced26a303735e7d958343a5ed3 /guide/pytest.html
parentUpdate & sort the feed list (diff)
downloadpython-c01c3cbddc8ea0575bbea41b644f14704fff7741.tar.gz
python-c01c3cbddc8ea0575bbea41b644f14704fff7741.tar.bz2
python-c01c3cbddc8ea0575bbea41b644f14704fff7741.zip
Rebuild with Sphinx 6.1.3
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'guide/pytest.html')
-rw-r--r--guide/pytest.html139
1 files changed, 68 insertions, 71 deletions
diff --git a/guide/pytest.html b/guide/pytest.html
index 88cf1ab..1613a2c 100644
--- a/guide/pytest.html
+++ b/guide/pytest.html
@@ -10,9 +10,6 @@
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
- <script src="_static/jquery.js"></script>
- <script src="_static/underscore.js"></script>
- <script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/sphinx_highlight.js"></script>
<link rel="index" title="Index" href="genindex.html" />
@@ -42,8 +39,8 @@
<p>A few packages use <a class="reference external" href="https://docs.pytest.org/en/stable/example/markers.html">custom pytest markers</a> to indicate e.g. tests
requiring Internet access. These markers can be used to conveniently
disable whole test groups, e.g.:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_test<span class="o">()</span> <span class="o">{</span>
- epytest -m <span class="s1">&#39;not network&#39;</span> dask
+<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>-m<span class="w"> </span><span class="s1">&#39;not network&#39;</span><span class="w"> </span>dask
<span class="o">}</span>
</pre></div>
</div>
@@ -70,22 +67,22 @@ test files or tests to be ignored or deselected respectively. These
variables can be used in global scope to avoid redefining
<code class="docutils literal notranslate"><span class="pre">python_test()</span></code>. However, combining them with additional conditions
requires using the local scope.</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_test<span class="o">()</span> <span class="o">{</span>
- <span class="nb">local</span> <span class="nv">EPYTEST_IGNORE</span><span class="o">=(</span>
- <span class="c1"># ignore whole file with missing dep</span>
- tests/test_client.py
- <span class="o">)</span>
- <span class="nb">local</span> <span class="nv">EPYTEST_DESELECT</span><span class="o">=(</span>
- <span class="c1"># deselect a single test</span>
- <span class="s1">&#39;tests/utils/test_general.py::test_filename&#39;</span>
- <span class="c1"># deselect a parametrized test based on first param</span>
- <span class="s1">&#39;tests/test_transport.py::test_transport_works[eventlet&#39;</span>
- <span class="o">)</span>
- <span class="o">[[</span> <span class="si">${</span><span class="nv">EPYTHON</span><span class="si">}</span> <span class="o">==</span> python3.6 <span class="o">]]</span> <span class="o">&amp;&amp;</span> <span class="nv">EPYTEST_DESELECT</span><span class="o">+=(</span>
- <span class="c1"># deselect a test for py3.6 only</span>
- <span class="s1">&#39;tests/utils/test_contextvars.py::test_leaks[greenlet]&#39;</span>
- <span class="o">)</span>
- epytest
+<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><span class="nb">local</span><span class="w"> </span><span class="nv">EPYTEST_IGNORE</span><span class="o">=(</span>
+<span class="w"> </span><span class="c1"># ignore whole file with missing dep</span>
+<span class="w"> </span>tests/test_client.py
+<span class="w"> </span><span class="o">)</span>
+<span class="w"> </span><span class="nb">local</span><span class="w"> </span><span class="nv">EPYTEST_DESELECT</span><span class="o">=(</span>
+<span class="w"> </span><span class="c1"># deselect a single test</span>
+<span class="w"> </span><span class="s1">&#39;tests/utils/test_general.py::test_filename&#39;</span>
+<span class="w"> </span><span class="c1"># deselect a parametrized test based on first param</span>
+<span class="w"> </span><span class="s1">&#39;tests/test_transport.py::test_transport_works[eventlet&#39;</span>
+<span class="w"> </span><span class="o">)</span>
+<span class="w"> </span><span class="o">[[</span><span class="w"> </span><span class="si">${</span><span class="nv">EPYTHON</span><span class="si">}</span><span class="w"> </span><span class="o">==</span><span class="w"> </span>python3.6<span class="w"> </span><span class="o">]]</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="nv">EPYTEST_DESELECT</span><span class="o">+=(</span>
+<span class="w"> </span><span class="c1"># deselect a test for py3.6 only</span>
+<span class="w"> </span><span class="s1">&#39;tests/utils/test_contextvars.py::test_leaks[greenlet]&#39;</span>
+<span class="w"> </span><span class="o">)</span>
+<span class="w"> </span>epytest
<span class="o">}</span>
</pre></div>
</div>
@@ -101,9 +98,9 @@ in <code class="docutils literal notranslate"><span class="pre">setup_requires</
<code class="docutils literal notranslate"><span class="pre">setup.py</span></code> is being run, even if the user has no intention of running
tests. If this is the case, the dependency must be stripped.</p>
<p>The recommended method of stripping it is to use sed:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_prepare_all<span class="o">()</span> <span class="o">{</span>
- sed -i -e <span class="s1">&#39;/pytest-runner/d&#39;</span> setup.py <span class="o">||</span> die
- distutils-r1_python_prepare_all
+<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_prepare_all<span class="o">()</span><span class="w"> </span><span class="o">{</span>
+<span class="w"> </span>sed<span class="w"> </span>-i<span class="w"> </span>-e<span class="w"> </span><span class="s1">&#39;/pytest-runner/d&#39;</span><span class="w"> </span>setup.py<span class="w"> </span><span class="o">||</span><span class="w"> </span>die
+<span class="w"> </span>distutils-r1_python_prepare_all
<span class="o">}</span>
</pre></div>
</div>
@@ -123,7 +120,7 @@ to the maintainer’s discretion to decide whether this is justified.</p>
(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 multiprocessing
+<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">&quot;</span>
<span class="s2"> test? (</span>
@@ -131,10 +128,10 @@ make options for the job number, e.g.:</p>
<span class="s2"> )</span>
<span class="s2">&quot;</span>
-distutils_enable_tests pytest
+distutils_enable_tests<span class="w"> </span>pytest
-python_test<span class="o">()</span> <span class="o">{</span>
- epytest -n <span class="s2">&quot;</span><span class="k">$(</span>makeopts_jobs<span class="k">)</span><span class="s2">&quot;</span>
+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">&quot;</span><span class="k">$(</span>makeopts_jobs<span class="k">)</span><span class="s2">&quot;</span>
<span class="o">}</span>
</pre></div>
</div>
@@ -160,9 +157,9 @@ to pass <code class="docutils literal notranslate"><span class="pre">-p</span> <
<p>In some cases, upstream packages only list them as dependencies
but do not use them automatically. In other cases, you will need
to strip options enabling them from <code class="docutils literal notranslate"><span class="pre">pytest.ini</span></code> or <code class="docutils literal notranslate"><span class="pre">setup.cfg</span></code>.</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>src_prepare<span class="o">()</span> <span class="o">{</span>
- sed -i -e <span class="s1">&#39;s:--cov=wheel::&#39;</span> setup.cfg <span class="o">||</span> die
- distutils-r1_src_prepare
+<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>src_prepare<span class="o">()</span><span class="w"> </span><span class="o">{</span>
+<span class="w"> </span>sed<span class="w"> </span>-i<span class="w"> </span>-e<span class="w"> </span><span class="s1">&#39;s:--cov=wheel::&#39;</span><span class="w"> </span>setup.cfg<span class="w"> </span><span class="o">||</span><span class="w"> </span>die
+<span class="w"> </span>distutils-r1_src_prepare
<span class="o">}</span>
</pre></div>
</div>
@@ -176,9 +173,9 @@ that do not expect them, to fail.</p>
<p>An example of such package used to be <code class="docutils literal notranslate"><span class="pre">dev-python/pytest-relaxed</span></code>.
To resolve problems due to the plugin, it was necessary to disable
it explicitly:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_test<span class="o">()</span> <span class="o">{</span>
- <span class="c1"># pytest-relaxed plugin makes our tests fail</span>
- epytest -p no:relaxed
+<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><span class="c1"># pytest-relaxed plugin makes our tests fail</span>
+<span class="w"> </span>epytest<span class="w"> </span>-p<span class="w"> </span>no:relaxed
<span class="o">}</span>
</pre></div>
</div>
@@ -198,12 +195,12 @@ to disable autoloading plugins, and <code class="docutils literal notranslate"><
plugins to load. The latter takes a comma-separated list of entry point
modules. To find the correct module names, look into
the <code class="docutils literal notranslate"><span class="pre">entry_points.txt</span></code> inside the package’s <code class="docutils literal notranslate"><span class="pre">.egg-info</span></code> directory.</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_test<span class="o">()</span> <span class="o">{</span>
- <span class="nb">local</span> -x <span class="nv">PYTEST_DISABLE_PLUGIN_AUTOLOAD</span><span class="o">=</span><span class="m">1</span>
- <span class="nb">local</span> -x <span class="nv">PYTEST_PLUGINS</span><span class="o">=</span>xdist.plugin,xdist.looponfail,pytest_forked
+<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><span class="nb">local</span><span class="w"> </span>-x<span class="w"> </span><span class="nv">PYTEST_DISABLE_PLUGIN_AUTOLOAD</span><span class="o">=</span><span class="m">1</span>
+<span class="w"> </span><span class="nb">local</span><span class="w"> </span>-x<span class="w"> </span><span class="nv">PYTEST_PLUGINS</span><span class="o">=</span>xdist.plugin,xdist.looponfail,pytest_forked
- distutils_install_for_testing
- epytest
+<span class="w"> </span>distutils_install_for_testing
+<span class="w"> </span>epytest
<span class="o">}</span>
</pre></div>
</div>
@@ -211,7 +208,7 @@ the <code class="docutils literal notranslate"><span class="pre">entry_points.tx
<section id="typeerror-make-test-flaky-got-an-unexpected-keyword-argument-reruns">
<h2>TypeError: _make_test_flaky() got an unexpected keyword argument ‘reruns’<a class="headerlink" href="#typeerror-make-test-flaky-got-an-unexpected-keyword-argument-reruns" title="Permalink to this heading">¶</a></h2>
<p>If you see a test error resembling the following:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>TypeError: _make_test_flaky<span class="o">()</span> got an unexpected keyword argument <span class="s1">&#39;reruns&#39;</span>
+<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>TypeError:<span class="w"> </span>_make_test_flaky<span class="o">()</span><span class="w"> </span>got<span class="w"> </span>an<span class="w"> </span>unexpected<span class="w"> </span>keyword<span class="w"> </span>argument<span class="w"> </span><span class="s1">&#39;reruns&#39;</span>
</pre></div>
</div>
<p>This means that the tests are being run via <a class="reference external" href="https://github.com/box/flaky/">flaky</a> plugin while
@@ -225,8 +222,8 @@ sure to depend on <code class="docutils literal notranslate"><span class="pre">d
<span class="s2"> dev-python/dev-python/pytest-rerunfailures[</span><span class="si">${</span><span class="nv">PYTHON_USEDEP</span><span class="si">}</span><span class="s2">]</span>
<span class="s2"> )&quot;</span>
-python_test<span class="o">()</span> <span class="o">{</span>
- epytest -p no:flaky
+python_test<span class="o">()</span><span class="w"> </span><span class="o">{</span>
+<span class="w"> </span>epytest<span class="w"> </span>-p<span class="w"> </span>no:flaky
<span class="o">}</span>
</pre></div>
</div>
@@ -236,7 +233,7 @@ python_test<span class="o">()</span> <span class="o">{</span>
<p>An <code class="docutils literal notranslate"><span class="pre">ImportPathMismatchError</span></code> generally indicates that the same Python
module (or one that supposedly looks the same) has been loaded twice
using different paths, e.g.:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>E _pytest.pathlib.ImportPathMismatchError: <span class="o">(</span><span class="s1">&#39;path&#39;</span>, <span class="s1">&#39;/usr/lib/pypy3.7/site-packages/path&#39;</span>, PosixPath<span class="o">(</span><span class="s1">&#39;/tmp/portage/dev-python/jaraco-path-3.3.1/work/jaraco.path-3.3.1/jaraco/path.py&#39;</span><span class="o">))</span>
+<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>E<span class="w"> </span>_pytest.pathlib.ImportPathMismatchError:<span class="w"> </span><span class="o">(</span><span class="s1">&#39;path&#39;</span>,<span class="w"> </span><span class="s1">&#39;/usr/lib/pypy3.7/site-packages/path&#39;</span>,<span class="w"> </span>PosixPath<span class="o">(</span><span class="s1">&#39;/tmp/portage/dev-python/jaraco-path-3.3.1/work/jaraco.path-3.3.1/jaraco/path.py&#39;</span><span class="o">))</span>
</pre></div>
</div>
<p>These problems are usually caused by pytest test discovery getting
@@ -247,14 +244,14 @@ relatively to the top directory, it loads it as <code class="docutils literal no
to the <code class="docutils literal notranslate"><span class="pre">jaraco</span></code> directory.</p>
<p>The simplest way to resolve this problem is to restrict the test
discovery to the actual test directories, e.g.:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_test<span class="o">()</span> <span class="o">{</span>
- epytest <span class="nb">test</span>
+<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><span class="nb">test</span>
<span class="o">}</span>
</pre></div>
</div>
<p>or:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python_test<span class="o">()</span> <span class="o">{</span>
- epytest --ignore jaraco
+<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>--ignore<span class="w"> </span>jaraco
<span class="o">}</span>
</pre></div>
</div>
@@ -295,31 +292,31 @@ plugins.</p>
<h2>Warnings<a class="headerlink" href="#warnings" title="Permalink to this heading">¶</a></h2>
<p>pytest captures all warnings from the test suite by default, and prints
a summary of them at the end of the test suite run:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">===============================</span> warnings <span class="nv">summary</span> <span class="o">===============================</span>
-asgiref/sync.py:135: <span class="m">1</span> warning
-tests/test_local.py: <span class="m">5</span> warnings
-tests/test_sync.py: <span class="m">12</span> warnings
-tests/test_sync_contextvars.py: <span class="m">1</span> warning
- /tmp/asgiref/asgiref/sync.py:135: DeprecationWarning: There is no current event loop
- self.main_event_loop <span class="o">=</span> asyncio.get_event_loop<span class="o">()</span>
+<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">===============================</span><span class="w"> </span>warnings<span class="w"> </span><span class="nv">summary</span><span class="w"> </span><span class="o">===============================</span>
+asgiref/sync.py:135:<span class="w"> </span><span class="m">1</span><span class="w"> </span>warning
+tests/test_local.py:<span class="w"> </span><span class="m">5</span><span class="w"> </span>warnings
+tests/test_sync.py:<span class="w"> </span><span class="m">12</span><span class="w"> </span>warnings
+tests/test_sync_contextvars.py:<span class="w"> </span><span class="m">1</span><span class="w"> </span>warning
+<span class="w"> </span>/tmp/asgiref/asgiref/sync.py:135:<span class="w"> </span>DeprecationWarning:<span class="w"> </span>There<span class="w"> </span>is<span class="w"> </span>no<span class="w"> </span>current<span class="w"> </span>event<span class="w"> </span>loop
+<span class="w"> </span>self.main_event_loop<span class="w"> </span><span class="o">=</span><span class="w"> </span>asyncio.get_event_loop<span class="o">()</span>
<span class="o">[</span>...<span class="o">]</span>
</pre></div>
</div>
<p>However, some projects go further and use <code class="docutils literal notranslate"><span class="pre">filterwarnings</span></code> option
to make (some) warnings fatal:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">====================================</span> <span class="nv">ERRORS</span> <span class="o">====================================</span>
-_____________________ ERROR collecting tests/test_sync.py ______________________
-tests/test_sync.py:577: <span class="k">in</span> &lt;module&gt;
- class ASGITest<span class="o">(</span>TestCase<span class="o">)</span>:
-tests/test_sync.py:583: <span class="k">in</span> ASGITest
- async def test_wrapped_case_is_collected<span class="o">(</span>self<span class="o">)</span>:
-asgiref/sync.py:135: <span class="k">in</span> __init__
- self.main_event_loop <span class="o">=</span> asyncio.get_event_loop<span class="o">()</span>
-E DeprecationWarning: There is no current event <span class="nv">loop</span>
-<span class="o">===========================</span> short <span class="nb">test</span> summary <span class="nv">info</span> <span class="o">============================</span>
-ERROR tests/test_sync.py - DeprecationWarning: There is no current event loop
-!!!!!!!!!!!!!!!!!!!! Interrupted: <span class="m">1</span> error during collection !!!!!!!!!!!!!!!!!!!!
-<span class="o">===============================</span> <span class="m">1</span> error <span class="k">in</span> <span class="m">0</span>.13s <span class="o">===============================</span>
+<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">====================================</span><span class="w"> </span><span class="nv">ERRORS</span><span class="w"> </span><span class="o">====================================</span>
+_____________________<span class="w"> </span>ERROR<span class="w"> </span>collecting<span class="w"> </span>tests/test_sync.py<span class="w"> </span>______________________
+tests/test_sync.py:577:<span class="w"> </span><span class="k">in</span><span class="w"> </span>&lt;module&gt;
+<span class="w"> </span>class<span class="w"> </span>ASGITest<span class="o">(</span>TestCase<span class="o">)</span>:
+tests/test_sync.py:583:<span class="w"> </span><span class="k">in</span><span class="w"> </span>ASGITest
+<span class="w"> </span>async<span class="w"> </span>def<span class="w"> </span>test_wrapped_case_is_collected<span class="o">(</span>self<span class="o">)</span>:
+asgiref/sync.py:135:<span class="w"> </span><span class="k">in</span><span class="w"> </span>__init__
+<span class="w"> </span>self.main_event_loop<span class="w"> </span><span class="o">=</span><span class="w"> </span>asyncio.get_event_loop<span class="o">()</span>
+E<span class="w"> </span>DeprecationWarning:<span class="w"> </span>There<span class="w"> </span>is<span class="w"> </span>no<span class="w"> </span>current<span class="w"> </span>event<span class="w"> </span><span class="nv">loop</span>
+<span class="o">===========================</span><span class="w"> </span>short<span class="w"> </span><span class="nb">test</span><span class="w"> </span>summary<span class="w"> </span><span class="nv">info</span><span class="w"> </span><span class="o">============================</span>
+ERROR<span class="w"> </span>tests/test_sync.py<span class="w"> </span>-<span class="w"> </span>DeprecationWarning:<span class="w"> </span>There<span class="w"> </span>is<span class="w"> </span>no<span class="w"> </span>current<span class="w"> </span>event<span class="w"> </span>loop
+!!!!!!!!!!!!!!!!!!!!<span class="w"> </span>Interrupted:<span class="w"> </span><span class="m">1</span><span class="w"> </span>error<span class="w"> </span>during<span class="w"> </span>collection<span class="w"> </span>!!!!!!!!!!!!!!!!!!!!
+<span class="o">===============================</span><span class="w"> </span><span class="m">1</span><span class="w"> </span>error<span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="m">0</span>.13s<span class="w"> </span><span class="o">===============================</span>
</pre></div>
</div>
<p>Unfortunately, this frequently means that warnings coming from
@@ -337,9 +334,9 @@ the installed code, it is acceptable to make them non-fatal. This can
be done either through removing the <code class="docutils literal notranslate"><span class="pre">filterwarnings</span></code> key from
<code class="docutils literal notranslate"><span class="pre">setup.cfg</span></code>, or adding an ignore entry. For example, the following
setting ignores <code class="docutils literal notranslate"><span class="pre">DeprecationWarning</span></code> in <code class="docutils literal notranslate"><span class="pre">test</span></code> directory:</p>
-<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nv">filterwarnings</span> <span class="o">=</span>
- error
- ignore::DeprecationWarning:test
+<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nv">filterwarnings</span><span class="w"> </span><span class="o">=</span>
+<span class="w"> </span>error
+<span class="w"> </span>ignore::DeprecationWarning:test
</pre></div>
</div>
</section>
@@ -435,7 +432,7 @@ setting ignores <code class="docutils literal notranslate"><span class="pre">Dep
&copy;2020, Michał Górny, license: CC BY 4.0.
|
- Powered by <a href="http://sphinx-doc.org/">Sphinx 5.3.0</a>
+ Powered by <a href="http://sphinx-doc.org/">Sphinx 6.1.3</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|