@@ -373,6 +373,30 @@ def test_foo(subtests):
373373 )
374374
375375
376+ def test_msg_not_a_string (
377+ pytester : pytest .Pytester , monkeypatch : pytest .MonkeyPatch
378+ ) -> None :
379+ monkeypatch .setenv ("COLUMNS" , "120" )
380+ pytester .makepyfile (
381+ """
382+ def test_int_msg(subtests):
383+ with subtests.test(42):
384+ assert False, "subtest failure"
385+
386+ def test_no_msg(subtests):
387+ with subtests.test():
388+ assert False, "subtest failure"
389+ """
390+ )
391+ result = pytester .runpytest ()
392+ result .stdout .fnmatch_lines (
393+ [
394+ "SUBFAILED[[]42[]] test_msg_not_a_string.py::test_int_msg - AssertionError: subtest failure" ,
395+ "SUBFAILED(<subtest>) test_msg_not_a_string.py::test_no_msg - AssertionError: subtest failure" ,
396+ ]
397+ )
398+
399+
376400@pytest .mark .parametrize ("flag" , ["--last-failed" , "--stepwise" ])
377401def test_subtests_last_failed_step_wise (pytester : pytest .Pytester , flag : str ) -> None :
378402 """Check that --last-failed and --step-wise correctly rerun tests with failed subtests."""
@@ -622,6 +646,32 @@ def test_foo(self):
622646 "SUBSKIPPED[[]subtest 1[]] [[]1[]] *.py:*: skip subtest 1"
623647 )
624648
649+ def test_msg_not_a_string (
650+ self , pytester : pytest .Pytester , monkeypatch : pytest .MonkeyPatch
651+ ) -> None :
652+ monkeypatch .setenv ("COLUMNS" , "120" )
653+ pytester .makepyfile (
654+ """
655+ from unittest import TestCase
656+
657+ class T(TestCase):
658+ def test_int_msg(self):
659+ with self.subTest(42):
660+ assert False, "subtest failure"
661+
662+ def test_no_msg(self):
663+ with self.subTest():
664+ assert False, "subtest failure"
665+ """
666+ )
667+ result = pytester .runpytest ()
668+ result .stdout .fnmatch_lines (
669+ [
670+ "SUBFAILED[[]42[]] test_msg_not_a_string.py::T::test_int_msg - AssertionError: subtest failure" ,
671+ "SUBFAILED(<subtest>) test_msg_not_a_string.py::T::test_no_msg - AssertionError: subtest failure" ,
672+ ]
673+ )
674+
625675
626676class TestCapture :
627677 def create_file (self , pytester : pytest .Pytester ) -> None :
0 commit comments