mardi 23 avril 2019

pytest-4.x.x: How to report SKIPPED tests like XFAILED?

When a test is xfailed the reason that is printed reports about test file, test class and test case, while the skipped test case reports only test file and a line where skip is called.

Here is a test example:

#!/usr/bin/env pytest

import pytest

@pytest.mark.xfail(reason="Reason of failure")
def test_1():
    pytest.fail("This will fail here")

@pytest.mark.skip(reason="Reason of skipping")
def test_2():
    pytest.fail("This will fail here")

This is the actual result:

pytest test_file.py -rsx
============================= test session starts =============================
platform linux -- Python 3.5.2, pytest-4.4.1, py-1.7.0, pluggy-0.9.0
rootdir: /home/ashot/questions
collected 2 items                                                             

test_file.py xs                                                         [100%]
=========================== short test summary info ===========================
SKIPPED [1] test_file.py:9: Reason of skipping
XFAIL test_file.py::test_1
  Reason of failure

==================== 1 skipped, 1 xfailed in 0.05 seconds =====================

But I would expect to get something like:

pytest test_file.py -rsx
============================= test session starts =============================
platform linux -- Python 3.5.2, pytest-4.4.1, py-1.7.0, pluggy-0.9.0
rootdir: /home/ashot/questions
collected 2 items                                                             

test_file.py xs                                                         [100%]
=========================== short test summary info ===========================
XFAIL test_file.py::test_1: Reason of failure
SKIPPED test_file.py::test_2: Reason of skipping

==================== 1 skipped, 1 xfailed in 0.05 seconds =====================

Aucun commentaire:

Enregistrer un commentaire