File: prettyassert.rst

package info (click to toggle)
nose2 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,912 kB
  • sloc: python: 10,721; makefile: 126
file content (48 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download | duplicates (3)
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
==============================
Use assert statements in tests
==============================

.. autoplugin :: nose2.plugins.prettyassert.PrettyAssert

assert statement inspection
---------------------------

The prettyassert plugin works by inspecting the stack frame which raised an
`AssertionError`. Unlike pytest's assertion rewriting code, it does not modify
the built-in `AssertionError`.

As a result, it is somewhat limited in its capabilities -- it
can only report the *bound* values from that stack frame. That means that this
type of statement works well:

.. code-block:: python

    x = f()
    y = g()
    assert x == y

but this type of statement does not:

.. code-block:: python

    assert f() == g()

It will still run, but the prettyassert will tell you that `f` and `g` are
functions, not what they evaluated to. This is probably not what you want.

attribute resolution
--------------------

The assertion inspection will resolve attributes, so that expressions like this
will work as well:

.. code-block:: python

    assert x.foo == 1

But note that the attribute `x.foo` will be resolved *twice* in this case, if
the assertion fails. Once when the assertion is evaluated, and again when it is
inspected.

As a result, properties with dynamic values may not behave as expected under
prettyassert inspection.