Skip to content

Commit 251fb0a

Browse files
committed
various documentation related refinements
--HG-- branch : trunk
1 parent a82a6bb commit 251fb0a

21 files changed

+253
-519
lines changed

doc/apiref.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ py.test reference documentation
99
xunit_setup.txt
1010
capture.txt
1111
monkeypatch.txt
12+
tmpdir.txt
1213
skipping.txt
1314
mark.txt
14-
doctest.txt
1515
recwarn.txt
1616
reporting.txt
17+
debugging.txt
18+
doctest.txt
19+
unittest.txt
1720

doc/capture.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
.. _`captures`:
3+
24
Capturing of stdout/stderr output
35
=========================================================
46

@@ -25,6 +27,7 @@ There are two ways in which ``py.test`` can perform capturing:
2527
output from code like ``sys.stderr.write(...)`` will be captured with
2628
this method.
2729

30+
.. _`disable capturing`:
2831

2932
You can influence output capturing mechanisms from the command line::
3033

doc/customize.txt

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Customizing and Extending py.test
55
basic test configuration
66
===================================
77

8-
available command line options
8+
Command line options
99
---------------------------------
1010

1111
You can see command line options by running::
@@ -26,10 +26,6 @@ allow to:
2626

2727
* `set option defaults`_
2828

29-
* `implement hooks`_
30-
31-
* `specify funcargs`_
32-
3329
or set particular variables to influence the testing process:
3430

3531
* ``pytest_plugins``: list of named plugins to load
@@ -68,25 +64,6 @@ To find out about the particular switches and type::
6864
This will print information about all options in your
6965
environment, including your local plugins.
7066

71-
.. _`basetemp`:
72-
73-
Temporary directories
74-
-------------------------------------------
75-
76-
You can create directories by calling one of two methods
77-
on the config object:
78-
79-
- ``config.mktemp(basename)``: create and return a new tempdir
80-
81-
- ``config.ensuretemp(basename)``: create or return a new tempdir
82-
83-
temporary directories are created as sub directories of a per-session
84-
testdir and will keep around the directories of the last three test
85-
runs. You can set the base temporary directory through the command line
86-
`--basetemp`` option. When distributing tests on the same machine,
87-
``py.test`` takes care to configure a basetemp directory for the sub
88-
processes such that all temporary data lands below below a single
89-
per-test run basetemp directory.
9067

9168
.. _`function arguments`: funcargs.html
9269
.. _`extensions`:
@@ -226,7 +203,6 @@ If you want to look at the names of existing plugins, use
226203
the ``--traceconfig`` option.
227204

228205
.. _`well specified hooks`:
229-
.. _`implement hooks`:
230206

231207
py.test hook reference
232208
====================================
@@ -361,17 +337,21 @@ name. Given a filesystem ``fspath`` it is constructed as follows:
361337

362338
* import the root package as ``root``
363339

364-
Complete reference of objects involved in hooks
340+
Reference of important objects involved in hooks
365341
===========================================================
366342

367-
.. autoclass:: pytest.plugin.runner.CallInfo
343+
.. autoclass:: pytest._config.Config
368344
:members:
369345

370-
.. autoclass:: pytest.plugin.runner.TestReport
371-
:members:
346+
.. autoclass:: pytest.collect.Item
347+
:inherited-members:
372348

373349
.. autoclass:: pytest.collect.Node
374350
:members:
375351

376-
.. autoclass:: pytest.collect.Item
377-
:inherited-members:
352+
.. autoclass:: pytest.plugin.runner.CallInfo
353+
:members:
354+
355+
.. autoclass:: pytest.plugin.runner.TestReport
356+
:members:
357+

doc/debugging.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
Tracebacks and debugging Python failures
3+
=================================================================
4+
5+
Stopping after the first (or N) failures
6+
----------------------------------------------------
7+
8+
To stop the testing process after the first (N) failures::
9+
10+
py.test -x # stop after first failure
11+
py.test -maxfail=2 # stop after two failures
12+
13+
Modifying traceback printing
14+
----------------------------------------------------
15+
16+
Examples for modifying traceback printing::
17+
18+
py.test --showlocals # show local variables in tracebacks
19+
py.test -l # show local variables (shortcut)
20+
21+
py.test --tb=long # the default informative traceback formatting
22+
py.test --tb=native # the Python standard library formatting
23+
py.test --tb=short # a shorter traceback format
24+
py.test --tb=line # only one line per failure
25+
26+
Dropping to PDB (Python Debugger) on failures
27+
----------------------------------------------------
28+
29+
.. _PDB: http://docs.python.org/library/pdb.html
30+
31+
Python comes with a builtin Python debugger called PDB_. ``py.test``
32+
allows to drop into the PDB prompt via a command line option::
33+
34+
py.test --pdb
35+
36+
This will invoke the Python debugger on every failure. Often you might
37+
only want to do this for the first failing test to understand a certain
38+
failure situation::
39+
40+
py.test -x --pdb # drop to PDB on first failure, then end test session
41+
py.test --pdb --maxfail=3 # drop to PDB for the first three failures
42+
43+
44+
Setting a breakpoint / aka ``set_trace()``
45+
----------------------------------------------------
46+
47+
If you want to set a breakpoint and enter the ``pdb.set_trace()`` you
48+
can use a helper::
49+
50+
def test_function():
51+
...
52+
py.test.set_trace() # invoke PDB debugger and tracing
53+
54+
.. versionadded: 2.0.0
55+
56+
In previous versions you could only enter PDB tracing if
57+
you :ref:`disable capturing`.
58+
59+

doc/doctest.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ and another like this::
4343
then you can just invoke ``py.test`` without command line options::
4444

4545
$ py.test
46-
============================= test session starts ==============================
46+
=========================== test session starts ============================
4747
platform linux2 -- Python 2.6.5 -- pytest-2.0.0dev0
48-
test path 1: /tmp/doc-exec-224
48+
test path 1: /tmp/doc-exec-288
4949

5050
conftest.py .
5151
example.rst .
5252
mymodule.py .
5353

54-
=========================== 3 passed in 0.01 seconds ===========================
54+
========================= 3 passed in 0.01 seconds =========================

doc/example/test_collectonly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def test_function():
55
pass
66

77
class TestClass:
8-
def test_method():
8+
def test_method(self):
99
pass
10-
def test_anothermethod():
10+
def test_anothermethod(self):
1111
pass

doc/funcargs.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ into a test module::
3131
Running the test looks like this::
3232

3333
$ py.test test_simplefactory.py
34-
============================= test session starts ==============================
34+
=========================== test session starts ============================
3535
platform linux2 -- Python 2.6.5 -- pytest-2.0.0dev0
3636
test path 1: test_simplefactory.py
3737

3838
test_simplefactory.py F
3939

40-
=================================== FAILURES ===================================
41-
________________________________ test_function _________________________________
40+
================================= FAILURES =================================
41+
______________________________ test_function _______________________________
4242

4343
myfuncarg = 42
4444

@@ -47,7 +47,7 @@ Running the test looks like this::
4747
E assert 42 == 17
4848

4949
test_simplefactory.py:5: AssertionError
50-
=========================== 1 failed in 0.02 seconds ===========================
50+
========================= 1 failed in 0.02 seconds =========================
5151

5252
This means that the test function was called with a ``myfuncarg`` value
5353
of ``42`` and the assert fails accordingly. Here is how py.test
@@ -129,7 +129,7 @@ Basic generated test example
129129

130130
Let's consider this test module::
131131

132-
# content of ./test_example.py
132+
# content of test_example.py
133133
def pytest_generate_tests(metafunc):
134134
if "numiter" in metafunc.funcargnames:
135135
for i in range(10):
@@ -141,14 +141,14 @@ Let's consider this test module::
141141
Running this::
142142

143143
$ py.test test_example.py
144-
============================= test session starts ==============================
144+
=========================== test session starts ============================
145145
platform linux2 -- Python 2.6.5 -- pytest-2.0.0dev0
146146
test path 1: test_example.py
147147

148148
test_example.py .........F
149149

150-
=================================== FAILURES ===================================
151-
_________________________________ test_func[9] _________________________________
150+
================================= FAILURES =================================
151+
_______________________________ test_func[9] _______________________________
152152

153153
numiter = 9
154154

@@ -157,7 +157,7 @@ Running this::
157157
E assert 9 < 9
158158

159159
test_example.py:7: AssertionError
160-
====================== 1 failed, 9 passed in 0.04 seconds ======================
160+
==================== 1 failed, 9 passed in 0.04 seconds ====================
161161

162162
Here is what happens in detail:
163163

doc/monkeypatch.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ will be undone.
3838

3939
.. background check:
4040
$ py.test
41-
============================= test session starts ==============================
41+
=========================== test session starts ============================
4242
platform linux2 -- Python 2.6.5 -- pytest-2.0.0dev0
43-
test path 1: /tmp/doc-exec-232
43+
test path 1: /tmp/doc-exec-296
4444

45-
=============================== in 0.00 seconds ===============================
45+
============================= in 0.00 seconds =============================
4646

4747
Method reference of the monkeypatch function argument
4848
-----------------------------------------------------

doc/test/plugin/capturelog.txt

Lines changed: 0 additions & 86 deletions
This file was deleted.

doc/test/plugin/hooklog.txt

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)