Lessons Learned

contact@vinta.com.br

pytest-xdist allows you to run failing tests in a loop inside a subprocess until it passes by looking for file changes to re-run previously failing tests. You can take advantage of it by having pytest-xdist installed and passing the command line flag -f or --looponfail to your pytest command. For more info see: https://docs.pytest.org/en/3.0.0/xdist.html#xdist-pytest-distributed-testing-plugin

Did you like?
1

pytest makes it easier to flag tests that are expected to fail. It's really useful when in development, e.g., feature not yet implement or bug not totally fixed. Making use of it is as simple as:

import pytest

@pytest.mark.xfail
def test_xpto():
    ...

This way, it'll be presented differently in the terminal report and one can track whether a test is failing as expected or unexpectedly passing.

While the test marked as expected to fail will be presented as xfailed in the test summary, if it passes it'll be displayed as xpassed and when that happens it's not displayed as passed because that test was marked to expect failure.

One can even go further and set a reason to why a test is expected to fail, one can set a reason:

import pytest

@pytest.mark.xfail(reason="feature not totally implemented")
def test_xpto():
    ...

To display this reason in the test summary, one can use the -r option with the corresponding short letters shown in progress(x for xfail and/or X for xpass), e.g. pytest -rxX.

For more information, check the documentation at: https://docs.pytest.org/en/latest/skipping.html#xfail-mark-test-functions-as-expected-to-fail

Did you like?
1