60 lines
1.8 KiB
Plaintext
60 lines
1.8 KiB
Plaintext
|
|
Tracebacks and debugging Python failures
|
|
=================================================================
|
|
|
|
Stopping after the first (or N) failures
|
|
----------------------------------------------------
|
|
|
|
To stop the testing process after the first (N) failures::
|
|
|
|
py.test -x # stop after first failure
|
|
py.test -maxfail=2 # stop after two failures
|
|
|
|
Modifying traceback printing
|
|
----------------------------------------------------
|
|
|
|
Examples for modifying traceback printing::
|
|
|
|
py.test --showlocals # show local variables in tracebacks
|
|
py.test -l # show local variables (shortcut)
|
|
|
|
py.test --tb=long # the default informative traceback formatting
|
|
py.test --tb=native # the Python standard library formatting
|
|
py.test --tb=short # a shorter traceback format
|
|
py.test --tb=line # only one line per failure
|
|
|
|
Dropping to PDB (Python Debugger) on failures
|
|
----------------------------------------------------
|
|
|
|
.. _PDB: http://docs.python.org/library/pdb.html
|
|
|
|
Python comes with a builtin Python debugger called PDB_. ``py.test``
|
|
allows to drop into the PDB prompt via a command line option::
|
|
|
|
py.test --pdb
|
|
|
|
This will invoke the Python debugger on every failure. Often you might
|
|
only want to do this for the first failing test to understand a certain
|
|
failure situation::
|
|
|
|
py.test -x --pdb # drop to PDB on first failure, then end test session
|
|
py.test --pdb --maxfail=3 # drop to PDB for the first three failures
|
|
|
|
|
|
Setting a breakpoint / aka ``set_trace()``
|
|
----------------------------------------------------
|
|
|
|
If you want to set a breakpoint and enter the ``pdb.set_trace()`` you
|
|
can use a helper::
|
|
|
|
def test_function():
|
|
...
|
|
py.test.set_trace() # invoke PDB debugger and tracing
|
|
|
|
.. versionadded: 2.0.0
|
|
|
|
In previous versions you could only enter PDB tracing if
|
|
you :ref:`disable capturing`.
|
|
|
|
|