Skip to content

Commit 1d88f4d

Browse files
committed
Start writing a debugging guide
1 parent 65dc1f5 commit 1d88f4d

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
lines changed

doc/examples/debugging-logging.out

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
$ pytest --log-cli-format='%(levelname)s: %(message)s' --log-cli-level=DEBUG debugging.py
2+
============================= test session starts ==============================
3+
platform linux -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
4+
rootdir: /home/user
5+
plugins: dependency-0.5.1
6+
collected 5 items
7+
8+
debugging.py::test_a
9+
-------------------------------- live log setup --------------------------------
10+
DEBUG: register setup debugging.py::test_a passed in session scope
11+
DEBUG: register setup test_a passed in module scope
12+
-------------------------------- live log call ---------------------------------
13+
DEBUG: register call debugging.py::test_a skipped in session scope
14+
DEBUG: register call test_a skipped in module scope
15+
XFAIL (deliberate fail) [ 20%]
16+
------------------------------ live log teardown -------------------------------
17+
DEBUG: register teardown debugging.py::test_a passed in session scope
18+
DEBUG: register teardown test_a passed in module scope
19+
20+
debugging.py::test_b
21+
-------------------------------- live log setup --------------------------------
22+
DEBUG: register setup debugging.py::test_b passed in session scope
23+
DEBUG: register setup test_b passed in module scope
24+
-------------------------------- live log call ---------------------------------
25+
DEBUG: register call debugging.py::test_b passed in session scope
26+
DEBUG: register call test_b passed in module scope
27+
PASSED [ 40%]
28+
------------------------------ live log teardown -------------------------------
29+
DEBUG: register teardown debugging.py::test_b passed in session scope
30+
DEBUG: register teardown test_b passed in module scope
31+
32+
debugging.py::test_c
33+
-------------------------------- live log setup --------------------------------
34+
DEBUG: check dependencies of test_c in module scope ...
35+
DEBUG: ... test_a has not succeeded
36+
INFO: skip test_c because it depends on test_a
37+
DEBUG: register setup debugging.py::test_c skipped in session scope
38+
DEBUG: register setup test_c skipped in module scope
39+
SKIPPED (test_c depends on test_a) [ 60%]
40+
------------------------------ live log teardown -------------------------------
41+
DEBUG: register teardown debugging.py::test_c passed in session scope
42+
DEBUG: register teardown test_c passed in module scope
43+
44+
debugging.py::test_d
45+
-------------------------------- live log setup --------------------------------
46+
DEBUG: check dependencies of test_d in module scope ...
47+
DEBUG: ... test_b succeeded
48+
DEBUG: register setup debugging.py::test_d passed in session scope
49+
DEBUG: register setup test_d passed in module scope
50+
-------------------------------- live log call ---------------------------------
51+
DEBUG: register call debugging.py::test_d passed in session scope
52+
DEBUG: register call test_d passed in module scope
53+
PASSED [ 80%]
54+
------------------------------ live log teardown -------------------------------
55+
DEBUG: register teardown debugging.py::test_d passed in session scope
56+
DEBUG: register teardown test_d passed in module scope
57+
58+
debugging.py::test_e
59+
-------------------------------- live log setup --------------------------------
60+
DEBUG: check dependencies of test_e in module scope ...
61+
DEBUG: ... test_b succeeded
62+
DEBUG: ... test_c has not succeeded
63+
INFO: skip test_e because it depends on test_c
64+
DEBUG: register setup debugging.py::test_e skipped in session scope
65+
DEBUG: register setup test_e skipped in module scope
66+
SKIPPED (test_e depends on test_c) [100%]
67+
------------------------------ live log teardown -------------------------------
68+
DEBUG: register teardown debugging.py::test_e passed in session scope
69+
DEBUG: register teardown test_e passed in module scope
70+
71+
72+
=================== 2 passed, 2 skipped, 1 xfailed in 0.03s ====================

doc/examples/debugging-summary.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$ pytest -rs debugging.py
2+
============================= test session starts ==============================
3+
platform linux -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
4+
rootdir: /home/user
5+
plugins: dependency-0.5.1
6+
collected 5 items
7+
8+
debugging.py x.s.s [100%]
9+
10+
=========================== short test summary info ============================
11+
SKIPPED [1] /usr/lib/python3.10/site-packages/pytest_dependency.py:103: test_c depends on test_a
12+
SKIPPED [1] /usr/lib/python3.10/site-packages/pytest_dependency.py:103: test_e depends on test_c
13+
=================== 2 passed, 2 skipped, 1 xfailed in 0.02s ====================

doc/examples/debugging-verbose.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$ pytest --verbose debugging.py
2+
============================= test session starts ==============================
3+
platform linux -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /usr/bin/python3
4+
cachedir: .pytest_cache
5+
rootdir: /home/user
6+
plugins: dependency-0.5.1
7+
collecting ... collected 5 items
8+
9+
debugging.py::test_a XFAIL (deliberate fail) [ 20%]
10+
debugging.py::test_b PASSED [ 40%]
11+
debugging.py::test_c SKIPPED (test_c depends on test_a) [ 60%]
12+
debugging.py::test_d PASSED [ 80%]
13+
debugging.py::test_e SKIPPED (test_e depends on test_c) [100%]
14+
15+
=================== 2 passed, 2 skipped, 1 xfailed in 0.03s ====================

doc/examples/debugging.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
@pytest.mark.dependency()
4+
@pytest.mark.xfail(reason="deliberate fail")
5+
def test_a():
6+
assert False
7+
8+
@pytest.mark.dependency()
9+
def test_b():
10+
pass
11+
12+
@pytest.mark.dependency(depends=["test_a"])
13+
def test_c():
14+
pass
15+
16+
@pytest.mark.dependency(depends=["test_b"])
17+
def test_d():
18+
pass
19+
20+
@pytest.mark.dependency(depends=["test_b", "test_c"])
21+
def test_e():
22+
pass

doc/src/debugging.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Debugging guide
2+
===============
3+
4+
This section is supposed to provide hints on what to check if
5+
pytest-dependency does not seem to behave as expected.
6+
7+
Example
8+
-------
9+
10+
Throughout this debugging guide, we will consider the following
11+
example:
12+
13+
.. literalinclude:: ../examples/debugging.py
14+
15+
Diagnostic tools
16+
----------------
17+
18+
pytest summary
19+
..............
20+
21+
You can request a short summary from pytest including information on
22+
skipped tests using the ``-rs`` `command line option`__:
23+
24+
.. literalinclude:: ../examples/debugging-summary.out
25+
26+
.. __: https://docs.pytest.org/en/stable/usage.html#detailed-summary-report
27+
28+
Verbose pytest output
29+
.....................
30+
31+
A list of all tests with their respective outcome will be displayed if
32+
you call pytest with the ``--verbose`` command line option:
33+
34+
.. literalinclude:: ../examples/debugging-verbose.out
35+
36+
Logging
37+
.......
38+
39+
pytest-dependency emits log messages when registering test results and
40+
when checking dependencies for a test. You can request these log
41+
messages to be displayed at runtime using `log command line options`__
42+
in the pytest call:
43+
44+
.. literalinclude:: ../examples/debugging-logging.out
45+
46+
.. __: https://docs.pytest.org/en/stable/logging.html#live-logs

doc/src/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Content of the documentation
1717
scope
1818
advanced
1919
names
20+
debugging
2021
configuration
2122
changelog
2223
reference

0 commit comments

Comments
 (0)