This file is indexed.

/usr/share/doc/python-pytest/html/assert.html is in python-pytest-doc 3.3.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>The writing and reporting of assertions in tests &#8212; pytest documentation</title>
    <link rel="stylesheet" href="_static/flasky.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '3.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/pytest1favi.ico"/>
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Pytest API and builtin fixtures" href="builtin.html" />
    <link rel="prev" title="Using pytest with an existing test suite" href="existingtestsuite.html" />
   
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">

  </head>
  <body>
  
  
  


    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="builtin.html" title="Pytest API and builtin fixtures"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="existingtestsuite.html" title="Using pytest with an existing test suite"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="contents.html">pytest-3.3</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="the-writing-and-reporting-of-assertions-in-tests">
<h1>The writing and reporting of assertions in tests<a class="headerlink" href="#the-writing-and-reporting-of-assertions-in-tests" title="Permalink to this headline"></a></h1>
<div class="section" id="asserting-with-the-assert-statement">
<span id="assert"></span><span id="assert-with-the-assert-statement"></span><span id="assertfeedback"></span><h2>Asserting with the <code class="docutils literal"><span class="pre">assert</span></code> statement<a class="headerlink" href="#asserting-with-the-assert-statement" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">pytest</span></code> allows you to use the standard python <code class="docutils literal"><span class="pre">assert</span></code> for verifying
expectations and values in Python tests.  For example, you can write the
following:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># content of test_assert1.py</span>
<span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
    <span class="k">return</span> <span class="mi">3</span>

<span class="k">def</span> <span class="nf">test_function</span><span class="p">():</span>
    <span class="k">assert</span> <span class="n">f</span><span class="p">()</span> <span class="o">==</span> <span class="mi">4</span>
</pre></div>
</div>
<p>to assert that your function returns a certain value. If this assertion fails
you will see the return value of the function call:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ pytest test_assert1.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 item

test_assert1.py F                                                    [100%]

================================= FAILURES =================================
______________________________ test_function _______________________________

    def test_function():
&gt;       assert f() == 4
E       assert 3 == 4
E        +  where 3 = f()

test_assert1.py:5: AssertionError
========================= 1 failed in 0.12 seconds =========================
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">pytest</span></code> has support for showing the values of the most common subexpressions
including calls, attributes, comparisons, and binary and unary
operators. (See <a class="reference internal" href="example/reportingdemo.html#tbreportdemo"><span class="std std-ref">Demo of Python failure reports with pytest</span></a>).  This allows you to use the
idiomatic python constructs without boilerplate code while not losing
introspection information.</p>
<p>However, if you specify a message with the assertion like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">assert</span> <span class="n">a</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;value was odd, should be even&quot;</span>
</pre></div>
</div>
<p>then no assertion introspection takes places at all and the message
will be simply shown in the traceback.</p>
<p>See <a class="reference internal" href="#assert-details"><span class="std std-ref">Advanced assertion introspection</span></a> for more information on assertion introspection.</p>
</div>
<div class="section" id="assertions-about-expected-exceptions">
<span id="assertraises"></span><h2>Assertions about expected exceptions<a class="headerlink" href="#assertions-about-expected-exceptions" title="Permalink to this headline"></a></h2>
<p>In order to write assertions about raised exceptions, you can use
<code class="docutils literal"><span class="pre">pytest.raises</span></code> as a context manager like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pytest</span>

<span class="k">def</span> <span class="nf">test_zero_division</span><span class="p">():</span>
    <span class="k">with</span> <span class="n">pytest</span><span class="o">.</span><span class="n">raises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">):</span>
        <span class="mi">1</span> <span class="o">/</span> <span class="mi">0</span>
</pre></div>
</div>
<p>and if you need to have access to the actual exception info you may use:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">test_recursion_depth</span><span class="p">():</span>
    <span class="k">with</span> <span class="n">pytest</span><span class="o">.</span><span class="n">raises</span><span class="p">(</span><span class="ne">RuntimeError</span><span class="p">)</span> <span class="k">as</span> <span class="n">excinfo</span><span class="p">:</span>
        <span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
            <span class="n">f</span><span class="p">()</span>
        <span class="n">f</span><span class="p">()</span>
    <span class="k">assert</span> <span class="s1">&#39;maximum recursion&#39;</span> <span class="ow">in</span> <span class="nb">str</span><span class="p">(</span><span class="n">excinfo</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">excinfo</span></code> is a <code class="docutils literal"><span class="pre">ExceptionInfo</span></code> instance, which is a wrapper around
the actual exception raised.  The main attributes of interest are
<code class="docutils literal"><span class="pre">.type</span></code>, <code class="docutils literal"><span class="pre">.value</span></code> and <code class="docutils literal"><span class="pre">.traceback</span></code>.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.0.</span></p>
</div>
<p>In the context manager form you may use the keyword argument
<code class="docutils literal"><span class="pre">message</span></code> to specify a custom failure message:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">raises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="s2">&quot;Expecting ZeroDivisionError&quot;</span><span class="p">):</span>
<span class="gp">... </span>   <span class="k">pass</span>
<span class="gp">... </span><span class="n">Failed</span><span class="p">:</span> <span class="n">Expecting</span> <span class="ne">ZeroDivisionError</span>
</pre></div>
</div>
<p>If you want to write test code that works on Python 2.4 as well,
you may also use two other ways to test for an expected exception:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span><span class="o">.</span><span class="n">raises</span><span class="p">(</span><span class="n">ExpectedException</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">pytest</span><span class="o">.</span><span class="n">raises</span><span class="p">(</span><span class="n">ExpectedException</span><span class="p">,</span> <span class="s2">&quot;func(*args, **kwargs)&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>both of which execute the specified function with args and kwargs and
asserts that the given <code class="docutils literal"><span class="pre">ExpectedException</span></code> is raised.  The reporter will
provide you with helpful output in case of failures such as <em>no
exception</em> or <em>wrong exception</em>.</p>
<p>Note that it is also possible to specify a &quot;raises&quot; argument to
<code class="docutils literal"><span class="pre">pytest.mark.xfail</span></code>, which checks that the test is failing in a more
specific way than just having any exception raised:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@pytest</span><span class="o">.</span><span class="n">mark</span><span class="o">.</span><span class="n">xfail</span><span class="p">(</span><span class="n">raises</span><span class="o">=</span><span class="ne">IndexError</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">test_f</span><span class="p">():</span>
    <span class="n">f</span><span class="p">()</span>
</pre></div>
</div>
<p>Using <code class="docutils literal"><span class="pre">pytest.raises</span></code> is likely to be better for cases where you are testing
exceptions your own code is deliberately raising, whereas using
<code class="docutils literal"><span class="pre">&#64;pytest.mark.xfail</span></code> with a check function is probably better for something
like documenting unfixed bugs (where the test describes what &quot;should&quot; happen)
or bugs in dependencies.</p>
<p>Also, the context manager form accepts a <code class="docutils literal"><span class="pre">match</span></code> keyword parameter to test
that a regular expression matches on the string representation of an exception
(like the <code class="docutils literal"><span class="pre">TestCase.assertRaisesRegexp</span></code> method from <code class="docutils literal"><span class="pre">unittest</span></code>):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pytest</span>

<span class="k">def</span> <span class="nf">myfunc</span><span class="p">():</span>
    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Exception 123 raised&quot;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">test_match</span><span class="p">():</span>
    <span class="k">with</span> <span class="n">pytest</span><span class="o">.</span><span class="n">raises</span><span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="n">match</span><span class="o">=</span><span class="sa">r</span><span class="s1">&#39;.* 123 .*&#39;</span><span class="p">):</span>
        <span class="n">myfunc</span><span class="p">()</span>
</pre></div>
</div>
<p>The regexp parameter of the <code class="docutils literal"><span class="pre">match</span></code> method is matched with the <code class="docutils literal"><span class="pre">re.search</span></code>
function. So in the above example <code class="docutils literal"><span class="pre">match='123'</span></code> would have worked as
well.</p>
</div>
<div class="section" id="assertions-about-expected-warnings">
<span id="assertwarns"></span><h2>Assertions about expected warnings<a class="headerlink" href="#assertions-about-expected-warnings" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.8.</span></p>
</div>
<p>You can check that code raises a particular warning using
<a class="reference internal" href="warnings.html#warns"><span class="std std-ref">pytest.warns</span></a>.</p>
</div>
<div class="section" id="making-use-of-context-sensitive-comparisons">
<span id="newreport"></span><h2>Making use of context-sensitive comparisons<a class="headerlink" href="#making-use-of-context-sensitive-comparisons" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
<p><code class="docutils literal"><span class="pre">pytest</span></code> has rich support for providing context-sensitive information
when it encounters comparisons.  For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># content of test_assert2.py</span>

<span class="k">def</span> <span class="nf">test_set_comparison</span><span class="p">():</span>
    <span class="n">set1</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="s2">&quot;1308&quot;</span><span class="p">)</span>
    <span class="n">set2</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="s2">&quot;8035&quot;</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">set1</span> <span class="o">==</span> <span class="n">set2</span>
</pre></div>
</div>
<p>if you run this module:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ pytest test_assert2.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 item

test_assert2.py F                                                    [100%]

================================= FAILURES =================================
___________________________ test_set_comparison ____________________________

    def test_set_comparison():
        set1 = set(&quot;1308&quot;)
        set2 = set(&quot;8035&quot;)
&gt;       assert set1 == set2
E       AssertionError: assert {&#39;0&#39;, &#39;1&#39;, &#39;3&#39;, &#39;8&#39;} == {&#39;0&#39;, &#39;3&#39;, &#39;5&#39;, &#39;8&#39;}
E         Extra items in the left set:
E         &#39;1&#39;
E         Extra items in the right set:
E         &#39;5&#39;
E         Use -v to get the full diff

test_assert2.py:5: AssertionError
========================= 1 failed in 0.12 seconds =========================
</pre></div>
</div>
<p>Special comparisons are done for a number of cases:</p>
<ul class="simple">
<li>comparing long strings: a context diff is shown</li>
<li>comparing long sequences: first failing indices</li>
<li>comparing dicts: different entries</li>
</ul>
<p>See the <a class="reference internal" href="example/reportingdemo.html#tbreportdemo"><span class="std std-ref">reporting demo</span></a> for many more examples.</p>
</div>
<div class="section" id="defining-your-own-assertion-comparison">
<h2>Defining your own assertion comparison<a class="headerlink" href="#defining-your-own-assertion-comparison" title="Permalink to this headline"></a></h2>
<p>It is possible to add your own detailed explanations by implementing
the <code class="docutils literal"><span class="pre">pytest_assertrepr_compare</span></code> hook.</p>
<dl class="function">
<dt>
<code class="descname">pytest_assertrepr_compare</code><span class="sig-paren">(</span><em>config</em>, <em>op</em>, <em>left</em>, <em>right</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/_pytest/hookspec.html#pytest_assertrepr_compare"><span class="viewcode-link">[source]</span></a></dt>
<dd><p>return explanation for comparisons in failing assert expressions.</p>
<p>Return None for no custom explanation, otherwise return a list
of strings.  The strings will be joined by newlines but any newlines
<em>in</em> a string will be escaped.  Note that all but the first line will
be indented slightly, the intention is for the first line to be a summary.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>config</strong> (<a class="reference internal" href="writing_plugins.html#_pytest.config.Config" title="_pytest.config.Config"><em>_pytest.config.Config</em></a>) -- pytest config object</td>
</tr>
</tbody>
</table>
</dd></dl>

<p>As an example consider adding the following hook in a <a class="reference internal" href="fixture.html#conftest-py"><span class="std std-ref">conftest.py</span></a>
file which provides an alternative explanation for <code class="docutils literal"><span class="pre">Foo</span></code> objects:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># content of conftest.py</span>
<span class="kn">from</span> <span class="nn">test_foocompare</span> <span class="k">import</span> <span class="n">Foo</span>
<span class="k">def</span> <span class="nf">pytest_assertrepr_compare</span><span class="p">(</span><span class="n">op</span><span class="p">,</span> <span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">):</span>
    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">left</span><span class="p">,</span> <span class="n">Foo</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">right</span><span class="p">,</span> <span class="n">Foo</span><span class="p">)</span> <span class="ow">and</span> <span class="n">op</span> <span class="o">==</span> <span class="s2">&quot;==&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="p">[</span><span class="s1">&#39;Comparing Foo instances:&#39;</span><span class="p">,</span>
                <span class="s1">&#39;   vals: </span><span class="si">%s</span><span class="s1"> != </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">left</span><span class="o">.</span><span class="n">val</span><span class="p">,</span> <span class="n">right</span><span class="o">.</span><span class="n">val</span><span class="p">)]</span>
</pre></div>
</div>
<p>now, given this test module:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># content of test_foocompare.py</span>
<span class="k">class</span> <span class="nc">Foo</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">val</span> <span class="o">=</span> <span class="n">val</span>

    <span class="k">def</span> <span class="nf">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">val</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">val</span>

<span class="k">def</span> <span class="nf">test_compare</span><span class="p">():</span>
    <span class="n">f1</span> <span class="o">=</span> <span class="n">Foo</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">f2</span> <span class="o">=</span> <span class="n">Foo</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
    <span class="k">assert</span> <span class="n">f1</span> <span class="o">==</span> <span class="n">f2</span>
</pre></div>
</div>
<p>you can run the test module and get the custom output defined in
the conftest file:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ pytest -q test_foocompare.py
F                                                                    [100%]
================================= FAILURES =================================
_______________________________ test_compare _______________________________

    def test_compare():
        f1 = Foo(1)
        f2 = Foo(2)
&gt;       assert f1 == f2
E       assert Comparing Foo instances:
E            vals: 1 != 2

test_foocompare.py:11: AssertionError
1 failed in 0.12 seconds
</pre></div>
</div>
</div>
<div class="section" id="advanced-assertion-introspection">
<span id="assert-introspection"></span><span id="assert-details"></span><h2>Advanced assertion introspection<a class="headerlink" href="#advanced-assertion-introspection" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.1.</span></p>
</div>
<p>Reporting details about a failing assertion is achieved by rewriting assert
statements before they are run.  Rewritten assert statements put introspection
information into the assertion failure message.  <code class="docutils literal"><span class="pre">pytest</span></code> only rewrites test
modules directly discovered by its test collection process, so asserts in
supporting modules which are not themselves test modules will not be rewritten.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p><code class="docutils literal"><span class="pre">pytest</span></code> rewrites test modules on import by using an import
hook to write new <code class="docutils literal"><span class="pre">pyc</span></code> files. Most of the time this works transparently.
However, if you are messing with import yourself, the import hook may
interfere.</p>
<p>If this is the case you have two options:</p>
<ul class="simple">
<li>Disable rewriting for a specific module by adding the string
<code class="docutils literal"><span class="pre">PYTEST_DONT_REWRITE</span></code> to its docstring.</li>
<li>Disable rewriting for all modules by using <code class="docutils literal"><span class="pre">--assert=plain</span></code>.</li>
</ul>
<p class="last">Additionally, rewriting will fail silently if it cannot write new <code class="docutils literal"><span class="pre">.pyc</span></code> files,
i.e. in a read-only filesystem or a zipfile.</p>
</div>
<p>For further information, Benjamin Peterson wrote up <a class="reference external" href="http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html">Behind the scenes of pytest's new assertion rewriting</a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.1: </span>Add assert rewriting as an alternate introspection technique.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.1: </span>Introduce the <code class="docutils literal"><span class="pre">--assert</span></code> option. Deprecate <code class="docutils literal"><span class="pre">--no-assert</span></code> and
<code class="docutils literal"><span class="pre">--nomagic</span></code>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.0: </span>Removes the <code class="docutils literal"><span class="pre">--no-assert</span></code> and <code class="docutils literal"><span class="pre">--nomagic</span></code> options.
Removes the <code class="docutils literal"><span class="pre">--assert=reinterp</span></code> option.</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="contents.html">
              <img class="logo" src="_static/pytest1.png" alt="Logo"/>
            </a></p><h3><a href="contents.html">Table Of Contents</a></h3>

<ul>
  <li><a href="index.html">Home</a></li>
  <li><a href="contents.html">Contents</a></li>
  <li><a href="getting-started.html">Install</a></li>
  <li><a href="example/index.html">Examples</a></li>
  <li><a href="customize.html">Customize</a></li>
  <li><a href="contact.html">Contact</a></li>
  <li><a href="talks.html">Talks/Posts</a></li>
  <li><a href="changelog.html">Changelog</a></li>
  <li><a href="backwards-compatibility.html">Backwards Compatibility</a></li>
  <li><a href="license.html">License</a></li>
</ul>
  <hr>
  <ul>
<li><a class="reference internal" href="#">The writing and reporting of assertions in tests</a><ul>
<li><a class="reference internal" href="#asserting-with-the-assert-statement">Asserting with the <code class="docutils literal"><span class="pre">assert</span></code> statement</a></li>
<li><a class="reference internal" href="#assertions-about-expected-exceptions">Assertions about expected exceptions</a></li>
<li><a class="reference internal" href="#assertions-about-expected-warnings">Assertions about expected warnings</a></li>
<li><a class="reference internal" href="#making-use-of-context-sensitive-comparisons">Making use of context-sensitive comparisons</a></li>
<li><a class="reference internal" href="#defining-your-own-assertion-comparison">Defining your own assertion comparison</a></li>
<li><a class="reference internal" href="#advanced-assertion-introspection">Advanced assertion introspection</a></li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
  <li><a href="contents.html">Documentation overview</a><ul>
      <li>Previous: <a href="existingtestsuite.html" title="previous chapter">Using pytest with an existing test suite</a></li>
      <li>Next: <a href="builtin.html" title="next chapter">Pytest API and builtin fixtures</a></li>
  </ul></li>
</ul><h3>Useful Links</h3>
<ul>
  <li><a href="index.html">The pytest Website</a></li>
  <li><a href="contributing.html">Contribution Guide</a></li>
  <li><a href="https://pypi.python.org/pypi/pytest">pytest @ PyPI</a></li>
  <li><a href="https://github.com/pytest-dev/pytest/">pytest @ GitHub</a></li>
  <li><a href="http://plugincompat.herokuapp.com/">3rd party plugins</a></li>
  <li><a href="https://github.com/pytest-dev/pytest/issues">Issue Tracker</a></li>
  <li><a href="https://media.readthedocs.org/pdf/pytest/latest/pytest.pdf">PDF Documentation</a>
</ul>

<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>

  <div class="footer">
    &copy; Copyright 2018, holger krekel and pytest-dev team.
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  </div>
  

  </body>
</html>