Skip to content

Commit 56aecfc

Browse files
authored
Merge pull request #4587 from nicoddemus/merge-master-into-features
Merge master into features
2 parents 1a9979a + 30c7a7b commit 56aecfc

File tree

9 files changed

+78
-24
lines changed

9 files changed

+78
-24
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Contributors include::
66
Aaron Coleman
77
Abdeali JK
88
Abhijeet Kasurde
9+
Adam Johnson
910
Ahn Ki-Wook
1011
Alan Velasco
1112
Alexander Johnson

changelog/4557.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Markers example documentation page updated to support latest pytest version.

changelog/4558.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update cache documentation example to correctly show cache hit and miss.

changelog/4580.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved detailed summary report documentation.

doc/en/cache.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,22 @@ across pytest invocations::
185185
import pytest
186186
import time
187187

188+
def expensive_computation():
189+
print("running expensive computation...")
190+
188191
@pytest.fixture
189192
def mydata(request):
190193
val = request.config.cache.get("example/value", None)
191194
if val is None:
192-
time.sleep(9*0.6) # expensive computation :)
195+
expensive_computation()
193196
val = 42
194197
request.config.cache.set("example/value", val)
195198
return val
196199

197200
def test_function(mydata):
198201
assert mydata == 23
199202

200-
If you run this command once, it will take a while because
201-
of the sleep:
203+
If you run this command for the first time, you can see the print statement:
202204

203205
.. code-block:: pytest
204206
@@ -217,7 +219,7 @@ of the sleep:
217219
1 failed in 0.12 seconds
218220
219221
If you run it a second time the value will be retrieved from
220-
the cache and this will be quick:
222+
the cache and nothing will be printed:
221223

222224
.. code-block:: pytest
223225

doc/en/example/markers.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ apply a marker to an individual test instance::
308308
@pytest.mark.foo
309309
@pytest.mark.parametrize(("n", "expected"), [
310310
(1, 2),
311-
pytest.mark.bar((1, 3)),
311+
pytest.param((1, 3), marks=pytest.mark.bar),
312312
(2, 3),
313313
])
314314
def test_increment(n, expected):
@@ -318,15 +318,6 @@ In this example the mark "foo" will apply to each of the three
318318
tests, whereas the "bar" mark is only applied to the second test.
319319
Skip and xfail marks can also be applied in this way, see :ref:`skip/xfail with parametrize`.
320320

321-
.. note::
322-
323-
If the data you are parametrizing happen to be single callables, you need to be careful
324-
when marking these items. ``pytest.mark.xfail(my_func)`` won't work because it's also the
325-
signature of a function being decorated. To resolve this ambiguity, you need to pass a
326-
reason argument:
327-
``pytest.mark.xfail(func_bar, reason="Issue#7")``.
328-
329-
330321
.. _`adding a custom marker from a plugin`:
331322

332323
Custom marker and command line option to control test runs

doc/en/fixture.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ different ``App`` instances and respective smtp servers. There is no
804804
need for the ``app`` fixture to be aware of the ``smtp_connection``
805805
parametrization because pytest will fully analyse the fixture dependency graph.
806806

807-
Note, that the ``app`` fixture has a scope of ``module`` and uses a
807+
Note that the ``app`` fixture has a scope of ``module`` and uses a
808808
module-scoped ``smtp_connection`` fixture. The example would still work if
809809
``smtp_connection`` was cached on a ``session`` scope: it is fine for fixtures to use
810810
"broader" scoped fixtures but not the other way round:

doc/en/getting-started.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ Installation and Getting Started
77

88
**PyPI package name**: `pytest <https://pypi.org/project/pytest/>`_
99

10-
**Dependencies**: `py <https://pypi.org/project/py/>`_,
11-
`colorama (Windows) <https://pypi.org/project/colorama/>`_,
12-
1310
**Documentation as PDF**: `download latest <https://media.readthedocs.org/pdf/pytest/latest/pytest.pdf>`_
1411

1512
``pytest`` is a framework that makes building simple and scalable tests easy. Tests are expressive and readable—no boilerplate code required. Get started in minutes with a small unit test or complex functional test for your application or library.

doc/en/usage.rst

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Detailed summary report
147147

148148
.. versionadded:: 2.9
149149

150-
The ``-r`` flag can be used to display test results summary at the end of the test session,
150+
The ``-r`` flag can be used to display a "short test summary info" at the end of the test session,
151151
making it easy in large test suites to get a clear picture of all failures, skips, xfails, etc.
152152

153153
Example:
@@ -158,9 +158,34 @@ Example:
158158
=========================== test session starts ============================
159159
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
160160
rootdir: $REGENDOC_TMPDIR, inifile:
161-
collected 0 items
162-
163-
======================= no tests ran in 0.12 seconds =======================
161+
collected 7 items
162+
163+
test_examples.py ..FEsxX [100%]
164+
165+
==================================== ERRORS ====================================
166+
_________________________ ERROR at setup of test_error _________________________
167+
file /Users/chainz/tmp/pytestratest/test_examples.py, line 17
168+
def test_error(unknown_fixture):
169+
E fixture 'unknown_fixture' not found
170+
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
171+
> use 'pytest --fixtures [testpath]' for help on them.
172+
173+
/Users/chainz/tmp/pytestratest/test_examples.py:17
174+
=================================== FAILURES ===================================
175+
__________________________________ test_fail ___________________________________
176+
177+
def test_fail():
178+
> assert 0
179+
E assert 0
180+
181+
test_examples.py:14: AssertionError
182+
=========================== short test summary info ============================
183+
FAIL test_examples.py::test_fail
184+
ERROR test_examples.py::test_error
185+
SKIP [1] test_examples.py:21: Example
186+
XFAIL test_examples.py::test_xfail
187+
XPASS test_examples.py::test_xpass
188+
= 1 failed, 2 passed, 1 skipped, 1 xfailed, 1 xpassed, 1 error in 0.07 seconds =
164189
165190
The ``-r`` options accepts a number of characters after it, with ``a`` used above meaning "all except passes".
166191

@@ -183,9 +208,44 @@ More than one character can be used, so for example to only see failed and skipp
183208
=========================== test session starts ============================
184209
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
185210
rootdir: $REGENDOC_TMPDIR, inifile:
186-
collected 0 items
211+
collected 2 items
212+
213+
test_examples.py Fs [100%]
214+
215+
=================================== FAILURES ===================================
216+
__________________________________ test_fail ___________________________________
217+
218+
def test_fail():
219+
> assert 0
220+
E assert 0
221+
222+
test_examples.py:14: AssertionError
223+
=========================== short test summary info ============================
224+
FAIL test_examples.py::test_fail
225+
SKIP [1] test_examples.py:21: Example
226+
===================== 1 failed, 1 skipped in 0.09 seconds ======================
227+
228+
Using ``p`` lists the passing tests, whilst ``P`` adds an extra section "PASSES" with those tests that passed but had
229+
captured output:
187230

188-
======================= no tests ran in 0.12 seconds =======================
231+
.. code-block:: pytest
232+
233+
$ pytest -rpP
234+
=========================== test session starts ============================
235+
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
236+
rootdir: $REGENDOC_TMPDIR, inifile:
237+
collected 2 items
238+
239+
test_examples.py .. [100%]
240+
=========================== short test summary info ============================
241+
PASSED test_examples.py::test_pass
242+
PASSED test_examples.py::test_pass_with_output
243+
244+
==================================== PASSES ====================================
245+
____________________________ test_pass_with_output _____________________________
246+
----------------------------- Captured stdout call -----------------------------
247+
Passing test
248+
=========================== 2 passed in 0.04 seconds ===========================
189249
190250
.. _pdb-option:
191251

0 commit comments

Comments
 (0)