summaryrefslogtreecommitdiff
blob: ef8025dd5730eb8164030a5f0e6e491cc2a343be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-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 &#8212; Gentoo Python Guide  documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=b3523f8e" />
    <link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=039e1c02" />
    <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=b3ba4146"></script>
    <script src="_static/doctools.js?v=888ff710"></script>
    <script src="_static/sphinx_highlight.js?v=4825356b"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Advanced concepts" href="concept.html" />
    <link rel="prev" title="Advanced dependencies" href="depend.html" />
   
  <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>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <section id="pytest-recipes">
<h1>pytest recipes<a class="headerlink" href="#pytest-recipes" title="Permalink to this heading"></a></h1>
<section id="skipping-tests-based-on-markers">
<h2>Skipping tests based on markers<a class="headerlink" href="#skipping-tests-based-on-markers" title="Permalink to this heading"></a></h2>
<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="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>
</section>
<section id="skipping-tests-based-on-paths-names">
<h2>Skipping tests based on paths/names<a class="headerlink" href="#skipping-tests-based-on-paths-names" title="Permalink to this heading"></a></h2>
<p>There are two primary methods of skipping tests based on path (and name)
in pytest: using <code class="docutils literal notranslate"><span class="pre">--ignore</span></code> and <code class="docutils literal notranslate"><span class="pre">--deselect</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">--ignore</span></code> causes pytest to entirely ignore a file or a directory
when collecting tests.  This works only for skipping whole files but it
ignores missing dependencies and other failures occurring while
importing the test file.</p>
<p><code class="docutils literal notranslate"><span class="pre">--deselect</span></code> causes pytest to skip the specific test or tests.  It can
be also used to select individual tests or even parametrized variants
of tests.</p>
<p>Both options can be combined to get tests to pass without having
to alter the test files.  They are preferable over suggestions from
skipping problematic tests when tests are installed as part
of the package.  They can also be easily applied conditionally to Python
interpreter.</p>
<p>The modern versions of eclasses provide two control variables,
<code class="docutils literal notranslate"><span class="pre">EPYTEST_IGNORE</span></code> and <code class="docutils literal notranslate"><span class="pre">EPYTEST_DESELECT</span></code> that can be used to list
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="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>
</section>
<section id="avoiding-the-dependency-on-pytest-runner">
<h2>Avoiding the dependency on pytest-runner<a class="headerlink" href="#avoiding-the-dependency-on-pytest-runner" title="Permalink to this heading"></a></h2>
<p><a class="reference external" href="https://pypi.org/project/pytest-runner/">pytest-runner</a> is a package providing <code class="docutils literal notranslate"><span class="pre">pytest</span></code> command to setuptools.
While it might be convenient upstream, there is no real reason to use
it in Gentoo packages.  It has no real advantage over calling pytest
directly.</p>
<p>Some packages declare the dependency on <code class="docutils literal notranslate"><span class="pre">pytest-runner</span></code>
in <code class="docutils literal notranslate"><span class="pre">setup_requires</span></code>.  As a result, the dependency is enforced whenever
<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="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>
</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="Permalink 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">&quot;</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">&quot;</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">&quot;</span><span class="k">$(</span>makeopts_jobs<span class="k">)</span><span class="s2">&quot;</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>
</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="Permalink to this heading"></a></h2>
<p>There is a number of pytest plugins that have little value to Gentoo
users.  They include plugins for test coverage
(<code class="docutils literal notranslate"><span class="pre">dev-python/pytest-cov</span></code>), coding style (<code class="docutils literal notranslate"><span class="pre">dev-python/pytest-flake8</span></code>)
and more.  Generally, packages should avoid using those plugins.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>As of 2022-01-24, <code class="docutils literal notranslate"><span class="pre">epytest</span></code> disables a few undesirable plugins
by default.  As a result, developers have a good chance
of experiencing failures due to hardcoded pytest options first,
even if they have the relevant plugins installed.</p>
<p>If your package <em>really</em> needs to use the specific plugin, you need
to pass <code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">&lt;plugin&gt;</span></code> explicitly to reenable it.</p>
</div>
<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="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>
</section>
<section id="explicitly-disabling-automatic-pytest-plugins">
<h2>Explicitly disabling automatic pytest plugins<a class="headerlink" href="#explicitly-disabling-automatic-pytest-plugins" title="Permalink to this heading"></a></h2>
<p>Besides plugins explicitly used by the package, there are a few pytest
plugins that enable themselves automatically for all test suites
when installed.  In some cases, their presence causes tests of packages
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="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>
</section>
<section id="expert-disabling-plugin-autoloading-entirely">
<h2>Expert: disabling plugin autoloading entirely<a class="headerlink" href="#expert-disabling-plugin-autoloading-entirely" title="Permalink to this heading"></a></h2>
<p>If a test suite invokes pytest recursively (this is particularly
the case when packaging other pytest plugins), the <code class="docutils literal notranslate"><span class="pre">-p</span></code> option
can be insufficient to disable problematic plugins, as it does not
get passed to the nested pytest invocations.  For these packages,
the next best thing is to use environment variables.</p>
<p>Unfortunately, environment variables can only be used to disable
autoloading entirely.  When doing that, you need to explicitly force
loading plugins that the test suite really needs.</p>
<p>This is done using two envvars: <code class="docutils literal notranslate"><span class="pre">PYTEST_DISABLE_PLUGIN_AUTOLOAD</span></code>
to disable autoloading plugins, and <code class="docutils literal notranslate"><span class="pre">PYTEST_PLUGINS</span></code> to specify
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="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

<span class="w">    </span>distutils_install_for_testing
<span class="w">    </span>epytest
<span class="o">}</span>
</pre></div>
</div>
</section>
<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:<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
the package in question expects <a class="reference external" href="https://github.com/pytest-dev/pytest-rerunfailures/">pytest-rerunfailures</a>.  This is
because both plugins utilize the same <code class="docutils literal notranslate"><span class="pre">&#64;pytest.mark.flaky</span></code> marker
but support different set of arguments.</p>
<p>To resolve the problem, explicitly disable the <code class="docutils literal notranslate"><span class="pre">flaky</span></code> plugin and make
sure to depend on <code class="docutils literal notranslate"><span class="pre">dev-python/pytest-rerunfailures</span></code>:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nv">BDEPEND</span><span class="o">=</span><span class="s2">&quot;</span>
<span class="s2">    test? (</span>
<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="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>
</section>
<section id="importpathmismatcherror">
<h2>ImportPathMismatchError<a class="headerlink" href="#importpathmismatcherror" title="Permalink to this heading"></a></h2>
<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<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
confused by namespace packages.  In this case, the <code class="docutils literal notranslate"><span class="pre">jaraco</span></code> directory
is a Python 3-style namespace but pytest is treating it as a potential
test directory.  Therefore, instead of loading it as <code class="docutils literal notranslate"><span class="pre">jaraco.path</span></code>
relatively to the top directory, it loads it as <code class="docutils literal notranslate"><span class="pre">path</span></code> relatively
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="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="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>
</section>
<section id="fixture-not-found">
<h2>fixture ‘…’ not found<a class="headerlink" href="#fixture-not-found" title="Permalink to this heading"></a></h2>
<p>Most of the time, a missing fixture indicates that some pytest plugin
is not installed.  In rare cases, it can signify an incompatible pytest
version or package issue.</p>
<p>The following table maps common fixture names to their respective
plugins.</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Fixture name</p></th>
<th class="head"><p>Package</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>event_loop</p></td>
<td><p>dev-python/pytest-asyncio</p></td>
</tr>
<tr class="row-odd"><td><p>freezer</p></td>
<td><p>dev-python/pytest-freezegun</p></td>
</tr>
<tr class="row-even"><td><p>httpbin</p></td>
<td><p>dev-python/pytest-httpbin</p></td>
</tr>
<tr class="row-odd"><td><p>loop</p></td>
<td><p>dev-python/pytest-aiohttp</p></td>
</tr>
<tr class="row-even"><td><p>mocker</p></td>
<td><p>dev-python/pytest-mock</p></td>
</tr>
</tbody>
</table>
</section>
<section id="warnings">
<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><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="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
a dependency trigger test failures in other packages.  Since making
warnings fatal is relatively common in the Python world, it is
recommended to:</p>
<ol class="arabic simple">
<li><p>Fix warnings in Python packages whenever possible, even if they
are not fatal to the package itself.</p></li>
<li><p>Do not enable new Python implementations if they trigger any new
warnings in the package.</p></li>
</ol>
<p>If the warnings come from issues in the package’s test suite rather than
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="w"> </span><span class="o">=</span>
<span class="w">    </span>error
<span class="w">    </span>ignore::DeprecationWarning:test
</pre></div>
</div>
</section>
</section>


          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html">Gentoo Python Guide</a></h1>








<h3>Navigation</h3>
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="preface.html">Preface</a></li>
<li class="toctree-l1"><a class="reference internal" href="interpreter.html">Python interpreters</a></li>
<li class="toctree-l1"><a class="reference internal" href="eclass.html">Choosing between Python eclasses</a></li>
<li class="toctree-l1"><a class="reference internal" href="basic.html">Common basics</a></li>
<li class="toctree-l1"><a class="reference internal" href="any.html">python-any-r1 — build-time dependency</a></li>
<li class="toctree-l1"><a class="reference internal" href="single.html">python-single-r1 — single-impl packages</a></li>
<li class="toctree-l1"><a class="reference internal" href="multi.html">python-r1 — multi-impl packages</a></li>
<li class="toctree-l1"><a class="reference internal" href="distutils.html">distutils-r1 — standard Python build systems</a></li>
<li class="toctree-l1"><a class="reference internal" href="test.html">Tests in Python packages</a></li>
<li class="toctree-l1"><a class="reference internal" href="distutils-legacy.html">distutils-r1 legacy concepts</a></li>
<li class="toctree-l1"><a class="reference internal" href="pypi.html">pypi — helper eclass for PyPI archives</a></li>
<li class="toctree-l1"><a class="reference internal" href="helper.html">Common helper functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="depend.html">Advanced dependencies</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">pytest recipes</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#skipping-tests-based-on-markers">Skipping tests based on markers</a></li>
<li class="toctree-l2"><a class="reference internal" href="#skipping-tests-based-on-paths-names">Skipping tests based on paths/names</a></li>
<li class="toctree-l2"><a class="reference internal" href="#avoiding-the-dependency-on-pytest-runner">Avoiding the dependency on pytest-runner</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="#avoiding-dependencies-on-other-pytest-plugins">Avoiding dependencies on other pytest plugins</a></li>
<li class="toctree-l2"><a class="reference internal" href="#explicitly-disabling-automatic-pytest-plugins">Explicitly disabling automatic pytest plugins</a></li>
<li class="toctree-l2"><a class="reference internal" href="#expert-disabling-plugin-autoloading-entirely">Expert: disabling plugin autoloading entirely</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="#fixture-not-found">fixture ‘…’ not found</a></li>
<li class="toctree-l2"><a class="reference internal" href="#warnings">Warnings</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="concept.html">Advanced concepts</a></li>
<li class="toctree-l1"><a class="reference internal" href="expert-multi.html">Expert python-r1 usage</a></li>
<li class="toctree-l1"><a class="reference internal" href="buildsys.html">Integration with build systems written in Python</a></li>
<li class="toctree-l1"><a class="reference internal" href="porting.html">Porting tips</a></li>
<li class="toctree-l1"><a class="reference internal" href="migration.html">Migration guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="qawarn.html">QA checks and warnings</a></li>
<li class="toctree-l1"><a class="reference internal" href="package-maintenance.html">Python package maintenance</a></li>
<li class="toctree-l1"><a class="reference internal" href="interpreter-maintenance.html">Maintenance of Python implementations</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="index.html">Documentation overview</a><ul>
      <li>Previous: <a href="depend.html" title="previous chapter">Advanced dependencies</a></li>
      <li>Next: <a href="concept.html" title="next chapter">Advanced concepts</a></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2020, Michał Górny, license: CC BY 4.0.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 7.1.1</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
      
      |
      <a href="_sources/pytest.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>