pytest: 9.0.2
operating system: any
When calling self.subTest(msg) with a non-string msg, the message is not printed when run via pytest.
In contrast, it is printed when run with unittest.
It is also printed when using the subtests fixture in a pytest test.
Example:
import unittest
class T(unittest.TestCase):
def test_int_msg(self):
with self.subTest(42):
assert False, "subtest failure"
if __name__ == '__main__':
unittest.main()
Run with unittest - message is printed:
FAIL: test_int_msg (__main__.T.test_int_msg) [42]
Run with pytest - message is replaced with <subtest>:
SUBFAILED(<subtest>) tests/subtest/test_subtest.py::T::test_int_msg - AssertionError: subtest failure
In contrast:
def test_int_msg(subtests):
with subtests.test(42):
assert False, "subtest failure"
Run with pytest - message is printed:
SUBFAILED[42] tests/subtest/test_subtest3.py::test_int_msg - AssertionError: subtest failure
pip listfrom the virtual environment you are usingpytest: 9.0.2
operating system: any
When calling
self.subTest(msg)with a non-stringmsg, the message is not printed when run via pytest.In contrast, it is printed when run with unittest.
It is also printed when using the
subtestsfixture in a pytest test.Example:
Run with unittest - message is printed:
Run with pytest - message is replaced with
<subtest>:In contrast:
Run with pytest - message is printed: