Debian Codegraph @

docs/plugins/prettyassert.rst

raw
1 ==============================
2 Use assert statements in tests
3 ==============================
4
5 .. autoplugin :: nose2.plugins.prettyassert.PrettyAssert
6
7 assert statement inspection
8 ---------------------------
9
10 The prettyassert plugin works by inspecting the stack frame which raised an
11 `AssertionError`. Unlike pytest's assertion rewriting code, it does not modify
12 the built-in `AssertionError`.
13
14 As a result, it is somewhat limited in its capabilities -- it
15 can only report the *bound* values from that stack frame. That means that this
16 type of statement works well:
17
18 .. code-block:: python
19
20 x = f()
21 y = g()
22 assert x == y
23
24 but this type of statement does not:
25
26 .. code-block:: python
27
28 assert f() == g()
29
30 It will still run, but the prettyassert will tell you that `f` and `g` are
31 functions, not what they evaluated to. This is probably not what you want.
32
33 attribute resolution
34 --------------------
35
36 The assertion inspection will resolve attributes, so that expressions like this
37 will work as well:
38
39 .. code-block:: python
40
41 assert x.foo == 1
42
43 But note that the attribute `x.foo` will be resolved *twice* in this case, if
44 the assertion fails. Once when the assertion is evaluated, and again when it is
45 inspected.
46
47 As a result, properties with dynamic values may not behave as expected under
48 prettyassert inspection.