Skip to content

Commit 125e89b

Browse files
Merge pull request #2194 from rjprins/remove-reinterp-from-docs
Remove mention of --assert=reinterp in documentation
2 parents 3dfdbaf + 46a9861 commit 125e89b

File tree

2 files changed

+10
-47
lines changed

2 files changed

+10
-47
lines changed

doc/en/assert.rst

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -262,50 +262,20 @@ Advanced assertion introspection
262262
.. versionadded:: 2.1
263263

264264

265-
Reporting details about a failing assertion is achieved either by rewriting
266-
assert statements before they are run or re-evaluating the assert expression and
267-
recording the intermediate values. Which technique is used depends on the
268-
location of the assert, ``pytest`` configuration, and Python version being used
269-
to run ``pytest``.
270-
271-
By default, ``pytest`` rewrites assert statements in test modules.
272-
Rewritten assert statements put introspection information into the assertion failure message.
273-
``pytest`` only rewrites test modules directly discovered by its test collection process, so
274-
asserts in supporting modules which are not themselves test modules will not be
275-
rewritten.
265+
Reporting details about a failing assertion is achieved by rewriting assert
266+
statements before they are run. Rewritten assert statements put introspection
267+
information into the assertion failure message. ``pytest`` only rewrites test
268+
modules directly discovered by its test collection process, so asserts in
269+
supporting modules which are not themselves test modules will not be rewritten.
276270

277271
.. note::
278272

279273
``pytest`` rewrites test modules on import. It does this by using an import
280-
hook to write a new pyc files. Most of the time this works transparently.
274+
hook to write new pyc files. Most of the time this works transparently.
281275
However, if you are messing with import yourself, the import hook may
282-
interfere. If this is the case, simply use ``--assert=reinterp`` or
283-
``--assert=plain``. Additionally, rewriting will fail silently if it cannot
284-
write new pycs, i.e. in a read-only filesystem or a zipfile.
285-
286-
If an assert statement has not been rewritten or the Python version is less than
287-
2.6, ``pytest`` falls back on assert reinterpretation. In assert
288-
reinterpretation, ``pytest`` walks the frame of the function containing the
289-
assert statement to discover sub-expression results of the failing assert
290-
statement. You can force ``pytest`` to always use assertion reinterpretation by
291-
passing the ``--assert=reinterp`` option.
292-
293-
Assert reinterpretation has a caveat not present with assert rewriting: If
294-
evaluating the assert expression has side effects you may get a warning that the
295-
intermediate values could not be determined safely. A common example of this
296-
issue is an assertion which reads from a file::
297-
298-
assert f.read() != '...'
299-
300-
If this assertion fails then the re-evaluation will probably succeed!
301-
This is because ``f.read()`` will return an empty string when it is
302-
called the second time during the re-evaluation. However, it is
303-
easy to rewrite the assertion and avoid any trouble::
304-
305-
content = f.read()
306-
assert content != '...'
307-
308-
All assert introspection can be turned off by passing ``--assert=plain``.
276+
interfere. If this is the case, use ``--assert=plain``. Additionally,
277+
rewriting will fail silently if it cannot write new pycs, i.e. in a read-only
278+
filesystem or a zipfile.
309279

310280
For further information, Benjamin Peterson wrote up `Behind the scenes of pytest's new assertion rewriting <http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_.
311281

@@ -318,3 +288,4 @@ For further information, Benjamin Peterson wrote up `Behind the scenes of pytest
318288

319289
.. versionchanged:: 3.0
320290
Removes the ``--no-assert`` and``--nomagic`` options.
291+
Removes the ``--assert=reinterp`` option.

doc/en/faq.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@ This completely avoids previous issues of confusing assertion-reporting.
6666
It also means, that you can use Python's ``-O`` optimization without losing
6767
assertions in test modules.
6868

69-
``pytest`` contains a second, mostly obsolete, assert debugging technique
70-
invoked via ``--assert=reinterpret``: When an ``assert`` statement fails, ``pytest`` re-interprets
71-
the expression part to show intermediate values. This technique suffers
72-
from a caveat that the rewriting does not: If your expression has side
73-
effects (better to avoid them anyway!) the intermediate values may not
74-
be the same, confusing the reinterpreter and obfuscating the initial
75-
error (this is also explained at the command line if it happens).
76-
7769
You can also turn off all assertion interaction using the
7870
``--assert=plain`` option.
7971

0 commit comments

Comments
 (0)