merge heads
This commit is contained in:
commit
4b4a2c8162
|
@ -132,9 +132,12 @@ See the :ref:`reporting demo <tbreportdemo>` for many more examples.
|
||||||
|
|
||||||
|
|
||||||
.. _assert-details:
|
.. _assert-details:
|
||||||
|
.. _`assert introspection`:
|
||||||
|
|
||||||
Assertion introspection details
|
Advanced assertion introspection
|
||||||
-------------------------------
|
----------------------------------
|
||||||
|
|
||||||
|
.. versionadded:: 2.1
|
||||||
|
|
||||||
Reporting details about the failing assertion is achieved either by rewriting
|
Reporting details about the failing assertion is achieved either by rewriting
|
||||||
assert statements before they are run or re-evaluating the assert expression and
|
assert statements before they are run or re-evaluating the assert expression and
|
||||||
|
|
|
@ -61,20 +61,10 @@ py.test found the ``test_answer`` function by following :ref:`standard test disc
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
You can simply use the ``assert`` statement for asserting
|
You can simply use the ``assert`` statement for asserting test
|
||||||
expectations because intermediate values will be presented to you.
|
expectations. pytest's :ref:`assert introspection` will intelligently
|
||||||
This is arguably easier than learning all the `the JUnit legacy
|
report intermediate values of the assert expression freeing
|
||||||
methods`_.
|
you from the need to learn the many names of `JUnit legacy methods`_.
|
||||||
|
|
||||||
However, there remains one caveat to using simple asserts: your
|
|
||||||
assertion expression should better be side-effect free. Because
|
|
||||||
after an assertion failed py.test will re-evaluate the expression
|
|
||||||
in order to present intermediate values. You will get a nice warning
|
|
||||||
and you can easily fix it: compute the value ahead of the assert and
|
|
||||||
then do the assertion. Or maybe just use the assert "explicit message"
|
|
||||||
syntax::
|
|
||||||
|
|
||||||
assert expr, "message" # show "message" if expr is not True
|
|
||||||
|
|
||||||
.. _`the JUnit legacy methods`: http://docs.python.org/library/unittest.html#test-cases
|
.. _`the JUnit legacy methods`: http://docs.python.org/library/unittest.html#test-cases
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue