Regendocs

This commit is contained in:
Bruno Oliveira
2019-01-05 17:32:16 +00:00
parent 5a8e674e92
commit d0e9b4812f
20 changed files with 532 additions and 384 deletions
+83 -61
View File
@@ -48,9 +48,9 @@ Let's run this without supplying our new option:
.. code-block:: pytest
$ pytest -q test_sample.py
F [100%]
================================= FAILURES =================================
_______________________________ test_answer ________________________________
F [100%]
====================================== FAILURES ======================================
____________________________________ test_answer _____________________________________
cmdopt = 'type1'
@@ -63,7 +63,7 @@ Let's run this without supplying our new option:
E assert 0
test_sample.py:6: AssertionError
--------------------------- Captured stdout call ---------------------------
-------------------------------- Captured stdout call --------------------------------
first
1 failed in 0.12 seconds
@@ -72,9 +72,9 @@ And now with supplying a command line option:
.. code-block:: pytest
$ pytest -q --cmdopt=type2
F [100%]
================================= FAILURES =================================
_______________________________ test_answer ________________________________
F [100%]
====================================== FAILURES ======================================
____________________________________ test_answer _____________________________________
cmdopt = 'type2'
@@ -87,7 +87,7 @@ And now with supplying a command line option:
E assert 0
test_sample.py:6: AssertionError
--------------------------- Captured stdout call ---------------------------
-------------------------------- Captured stdout call --------------------------------
second
1 failed in 0.12 seconds
@@ -126,12 +126,14 @@ directory with the above conftest.py:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 0 items
======================= no tests ran in 0.12 seconds =======================
============================ no tests ran in 0.12 seconds ============================
.. _`excontrolskip`:
@@ -186,30 +188,34 @@ and when running it will see a skipped "slow" test:
.. code-block:: pytest
$ pytest -rs # "-rs" means report details on the little 's'
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 2 items
test_module.py .s [100%]
========================= short test summary info ==========================
test_module.py .s [100%]
============================== short test summary info ===============================
SKIP [1] test_module.py:8: need --runslow option to run
=================== 1 passed, 1 skipped in 0.12 seconds ====================
======================== 1 passed, 1 skipped in 0.12 seconds =========================
Or run it including the ``slow`` marked test:
.. code-block:: pytest
$ pytest --runslow
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 2 items
test_module.py .. [100%]
test_module.py .. [100%]
========================= 2 passed in 0.12 seconds =========================
============================== 2 passed in 0.12 seconds ==============================
Writing well integrated assertion helpers
--------------------------------------------------
@@ -245,9 +251,9 @@ Let's run our little function:
.. code-block:: pytest
$ pytest -q test_checkconfig.py
F [100%]
================================= FAILURES =================================
______________________________ test_something ______________________________
F [100%]
====================================== FAILURES ======================================
___________________________________ test_something ___________________________________
def test_something():
> checkconfig(42)
@@ -344,13 +350,15 @@ which will add the string to the test header accordingly:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
project deps: mylib-1.1
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 0 items
======================= no tests ran in 0.12 seconds =======================
============================ no tests ran in 0.12 seconds ============================
.. regendoc:wipe
@@ -372,27 +380,31 @@ which will add info only when run with "--v":
.. code-block:: pytest
$ pytest -v
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
info1: did you know that ...
did you?
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collecting ... collected 0 items
======================= no tests ran in 0.12 seconds =======================
============================ no tests ran in 0.12 seconds ============================
and nothing when run plainly:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 0 items
======================= no tests ran in 0.12 seconds =======================
============================ no tests ran in 0.12 seconds ============================
profiling test duration
--------------------------
@@ -426,18 +438,20 @@ Now we can profile which test functions execute the slowest:
.. code-block:: pytest
$ pytest --durations=3
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 3 items
test_some_are_slow.py ... [100%]
test_some_are_slow.py ... [100%]
========================= slowest 3 test durations =========================
============================== slowest 3 test durations ==============================
0.30s call test_some_are_slow.py::test_funcslow2
0.20s call test_some_are_slow.py::test_funcslow1
0.10s call test_some_are_slow.py::test_funcfast
========================= 3 passed in 0.12 seconds =========================
============================== 3 passed in 0.12 seconds ==============================
incremental testing - test steps
---------------------------------------------------
@@ -500,15 +514,17 @@ If we run this:
.. code-block:: pytest
$ pytest -rx
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 4 items
test_step.py .Fx. [100%]
test_step.py .Fx. [100%]
================================= FAILURES =================================
____________________ TestUserHandling.test_modification ____________________
====================================== FAILURES ======================================
_________________________ TestUserHandling.test_modification _________________________
self = <test_step.TestUserHandling object at 0xdeadbeef>
@@ -517,10 +533,10 @@ If we run this:
E assert 0
test_step.py:11: AssertionError
========================= short test summary info ==========================
============================== short test summary info ===============================
XFAIL test_step.py::TestUserHandling::test_deletion
reason: previous test failed (test_modification)
============== 1 failed, 2 passed, 1 xfailed in 0.12 seconds ===============
=================== 1 failed, 2 passed, 1 xfailed in 0.12 seconds ====================
We'll see that ``test_deletion`` was not executed because ``test_modification``
failed. It is reported as an "expected failure".
@@ -583,18 +599,20 @@ We can run this:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 7 items
test_step.py .Fx. [ 57%]
a/test_db.py F [ 71%]
a/test_db2.py F [ 85%]
b/test_error.py E [100%]
test_step.py .Fx. [ 57%]
a/test_db.py F [ 71%]
a/test_db2.py F [ 85%]
b/test_error.py E [100%]
================================== ERRORS ==================================
_______________________ ERROR at setup of test_root ________________________
======================================= ERRORS =======================================
____________________________ ERROR at setup of test_root _____________________________
file $REGENDOC_TMPDIR/b/test_error.py, line 1
def test_root(db): # no db here, will error out
E fixture 'db' not found
@@ -602,8 +620,8 @@ We can run this:
> use 'pytest --fixtures [testpath]' for help on them.
$REGENDOC_TMPDIR/b/test_error.py:1
================================= FAILURES =================================
____________________ TestUserHandling.test_modification ____________________
====================================== FAILURES ======================================
_________________________ TestUserHandling.test_modification _________________________
self = <test_step.TestUserHandling object at 0xdeadbeef>
@@ -612,7 +630,7 @@ We can run this:
E assert 0
test_step.py:11: AssertionError
_________________________________ test_a1 __________________________________
______________________________________ test_a1 _______________________________________
db = <conftest.DB object at 0xdeadbeef>
@@ -622,7 +640,7 @@ We can run this:
E assert 0
a/test_db.py:2: AssertionError
_________________________________ test_a2 __________________________________
______________________________________ test_a2 _______________________________________
db = <conftest.DB object at 0xdeadbeef>
@@ -632,7 +650,7 @@ We can run this:
E assert 0
a/test_db2.py:2: AssertionError
========== 3 failed, 2 passed, 1 xfailed, 1 error in 0.12 seconds ==========
=============== 3 failed, 2 passed, 1 xfailed, 1 error in 0.12 seconds ===============
The two test modules in the ``a`` directory see the same ``db`` fixture instance
while the one test in the sister-directory ``b`` doesn't see it. We could of course
@@ -696,15 +714,17 @@ and run them:
.. code-block:: pytest
$ pytest test_module.py
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 2 items
test_module.py FF [100%]
test_module.py FF [100%]
================================= FAILURES =================================
________________________________ test_fail1 ________________________________
====================================== FAILURES ======================================
_____________________________________ test_fail1 _____________________________________
tmpdir = local('PYTEST_TMPDIR/test_fail10')
@@ -713,14 +733,14 @@ and run them:
E assert 0
test_module.py:2: AssertionError
________________________________ test_fail2 ________________________________
_____________________________________ test_fail2 _____________________________________
def test_fail2():
> assert 0
E assert 0
test_module.py:6: AssertionError
========================= 2 failed in 0.12 seconds =========================
============================== 2 failed in 0.12 seconds ==============================
you will have a "failures" file which contains the failing test ids::
@@ -797,17 +817,19 @@ and run it:
.. code-block:: pytest
$ pytest -s test_module.py
=========================== test session starts ============================
================================ test session starts =================================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('$REGENDOC_TMPDIR/.hypothesis/examples')
rootdir: $REGENDOC_TMPDIR, inifile:
plugins: hypothesis-3.x.y
collected 3 items
test_module.py Esetting up a test failed! test_module.py::test_setup_fails
Fexecuting test failed test_module.py::test_call_fails
F
================================== ERRORS ==================================
____________________ ERROR at setup of test_setup_fails ____________________
======================================= ERRORS =======================================
_________________________ ERROR at setup of test_setup_fails _________________________
@pytest.fixture
def other():
@@ -815,8 +837,8 @@ and run it:
E assert 0
test_module.py:7: AssertionError
================================= FAILURES =================================
_____________________________ test_call_fails ______________________________
====================================== FAILURES ======================================
__________________________________ test_call_fails ___________________________________
something = None
@@ -825,14 +847,14 @@ and run it:
E assert 0
test_module.py:15: AssertionError
________________________________ test_fail2 ________________________________
_____________________________________ test_fail2 _____________________________________
def test_fail2():
> assert 0
E assert 0
test_module.py:19: AssertionError
==================== 2 failed, 1 error in 0.12 seconds =====================
========================= 2 failed, 1 error in 0.12 seconds ==========================
You'll see that the fixture finalizers could use the precise reporting
information.