37 lines
1.1 KiB
Plaintext
37 lines
1.1 KiB
Plaintext
|
|
||
|
writing well integrated assertion helpers
|
||
|
========================================================
|
||
|
|
||
|
If you have a test helper function called from a test you can
|
||
|
use the ``pytest.fail``_ builtin to cleanly fail a test with a message.
|
||
|
The test support function will never itself show up in the traceback.
|
||
|
Example::
|
||
|
|
||
|
# content of test_checkconfig.py
|
||
|
import pytest
|
||
|
def checkconfig(x):
|
||
|
__tracebackhide__ = True
|
||
|
if not hasattr(x, "config"):
|
||
|
pytest.fail("not configured: %s" %(x,))
|
||
|
|
||
|
def test_something():
|
||
|
checkconfig(42)
|
||
|
|
||
|
The ``__tracebackhide__`` setting influences py.test showing
|
||
|
of tracebacks: the ``checkconfig`` function will not be shown
|
||
|
unless the ``--fulltrace`` command line option is specified.
|
||
|
Let's run our little function::
|
||
|
|
||
|
$ py.test -q
|
||
|
F
|
||
|
================================= FAILURES =================================
|
||
|
______________________________ test_something ______________________________
|
||
|
|
||
|
def test_something():
|
||
|
> checkconfig(42)
|
||
|
E Failed: not configured: 42
|
||
|
|
||
|
test_checkconfig.py:8: Failed
|
||
|
1 failed in 0.02 seconds
|
||
|
|