-rx and -rX should turn on output for xfail/xpass · Issue #11233 · pytest-dev/pytest (original) (raw)

This shows up in a discussion #9834 and another issue #10618.

---- More detail about problem and expectations ----

Observations:
Based on a simple test script below that includes test_pass, test_fail, test_xfail, test_xpass.

  1. Output and exception for test_fail but not for test_xfail.
    • I would have expected test_xfail to look mostly just like test_fail.
    • If there's a reason to NOT report exception traceback and output for xfails, we should have an option to turn it on.
  2. assert 1 == 2 is displayed in summary info for FAILED but not for XFAIL.
    • I can't come up with reason why this would be correct behavior.
    • assert 1 == 2 should show up for XFAIL also.
  3. -rP (which is included in -rA) is "pass with output", and it applies to PASSED, but not XPASS.

Opinion on how to fix this:

My opinions, of course. But this would follow the idea of "behavior with the least surprise". And it doesn't require any extra flags.

$ pip list
Package    Version
---------- -------
colorama   0.4.6
iniconfig  2.0.0
packaging  23.1
pip        23.2
pluggy     1.2.0
pytest     7.4.0
setuptools 65.5.0

Example: test_foo.py

import pytest

def test_pass(): print('in test_pass()') a, b = 1, 1 assert a == b

def test_fail(): print('in test_fail()') a, b = 1, 2 assert a == b

@pytest.mark.xfail def test_xfail(): print('in test_xfail()') a, b = 1, 2 assert a == b

@pytest.mark.xfail def test_xpass(): print('in test_xpass()') a, b = 1, 1 assert a == b

Current output:

$ pytest -rA test_foo.py
============================= test session starts =============================
platform win32 -- Python 3.11.0, pytest-7.4.0, pluggy-1.0.0
rootdir: C:\Users\okken\projects\instrument_updater
configfile: tox.ini
collected 4 items

test_foo.py .FxX                                                         [100%]

================================== FAILURES ===================================
__________________________________ test_fail __________________________________

    def test_fail():
        print('in test_fail()')
        a, b = 1, 2
>       assert a == b
E       assert 1 == 2

test_foo.py:11: AssertionError
---------------------------- Captured stdout call -----------------------------
in test_fail()
=================================== PASSES ====================================
__________________________________ test_pass __________________________________
---------------------------- Captured stdout call -----------------------------
in test_pass()
=========================== short test summary info ===========================
PASSED test_foo.py::test_pass
XFAIL test_foo.py::test_xfail
XPASS test_foo.py::test_xpass
FAILED test_foo.py::test_fail - assert 1 == 2
============== 1 failed, 1 passed, 1 xfailed, 1 xpassed in 0.28s ==============