Pytest 3.5 is released! Many console options have been added in this version. Strongly recommend to read about this options and apply their in work ๐Ÿ™‚

Among the features are present such as:

  • –show-capture – accepts no, stdout, stderr, log, or all (default) values. Now you can specify which output you want to see in the console.
  • –rootdir – allows you to customize the root directory
  • –nf, –new-first allows you to change the order of execution of tests and to perform new tests in the beginning
  • –last-failed-no-failures allows you to configure the behavior of the –last-failed option
  • –doctest-continue-on-failure – allows you not to stop on the first error and to continue the execution when you running doctest
  • –verbosity – this flag allows you to specify the level of detail explicitly

All options are noteworthy, but I would like to focus on one of them: –nf, –new-first. How this option works: Pytest takes from cache the list of all tests from the previous run and compares with the current run. If he meets tests that were not in the previous runs, then puts in a queue ahead. Next, the test queue is becoming in the order of aging changes to the test files.For example, there are 2 files with 2 tests in each test_1.py and test_2.py. Let’s say we just changed the file test_2.py and made changes in some test. If you run in normal mode, firstly will be added the tests from test_1.py, then from test_2.py.

$ pytest tests -v
======================================================= test session starts ========================================================
platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0 -- /home/username/examples/env/bin/python
cachedir: .pytest_cache
rootdir: /home/username/examples, inifile:
collected 4 items
tests/test_1.py::test_1 PASSED [ 25%]
tests/test_1.py::test_2 PASSED [ 50%]
tests/test_2.py::test_1 PASSED [ 75%]
tests/test_2.py::test_2 PASSED [100%]

===================================================== 4 passed in 0.02 seconds =====================================================

In case if you run pytest with –new-first option, the order will change, and firstly tests will run from the file test_2.py and then from test_1.py.

$ pytest tests --nf -v
======================================================= test session starts ========================================================
platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0 -- /home/username/examples/env/bin/python
cachedir: .pytest_cache
rootdir: /home/username/examples, inifile:
collected 4 items
tests/test_2.py::test_1 PASSED [ 25%]
tests/test_2.py::test_2 PASSED [ 50%]
tests/test_1.py::test_1 PASSED [ 75%]
tests/test_1.py::test_2 PASSED [100%]

===================================================== 4 passed in 0.02 seconds =====================================================

At the same time, if there is a new test, which was not in the previous run, it will be run the first:

$ pytest tests --nf -v
======================================================= test session starts ========================================================
platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0 -- /home/username/examples/env/bin/python
cachedir: .pytest_cache
rootdir: /home/username/examples, inifile:
collected 5 items
tests/test_2.py::test_3 PASSED [ 20%]
tests/test_2.py::test_1 PASSED [ 40%]
tests/test_2.py::test_2 PASSED [ 60%]
tests/test_1.py::test_1 PASSED [ 80%]
tests/test_1.py::test_2 PASSED [100%]

===================================================== 5 passed in 0.02 seconds =====================================================
Please follow and like us:
error

Leave a Reply

avatar