Skip to content

Commit 6b700f4

Browse files
authored
subtests: avoid double saferepr() (#14213)
#13963 makes sure that values of `SubtestContext.kwargs` are strings by applying `saferepr()`. Thus, there is no need to apply `saferepr()` again for the description. Avoiding the second `saferepr()` results in nicer output and avoids a change in the output compared to previous pytest versions.
1 parent f081bfb commit 6b700f4

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/_pytest/subtests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _sub_test_description(self) -> str:
9191
parts.append(f"[{self.context.msg}]")
9292
if self.context.kwargs:
9393
params_desc = ", ".join(
94-
f"{k}={saferepr(v)}" for (k, v) in self.context.kwargs.items()
94+
f"{k}={v}" for (k, v) in self.context.kwargs.items()
9595
)
9696
parts.append(f"({params_desc})")
9797
return " ".join(parts) or "(<subtest>)"

testing/test_subtests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ def test_foo(subtests, x):
305305
result = pytester.runpytest("-v")
306306
result.stdout.fnmatch_lines(
307307
[
308-
"*.py::test_foo[[]0[]] SUBFAILED[[]custom[]] (i='1') *[[] 50%[]]",
308+
"*.py::test_foo[[]0[]] SUBFAILED[[]custom[]] (i=1) *[[] 50%[]]",
309309
"*.py::test_foo[[]0[]] FAILED *[[] 50%[]]",
310-
"*.py::test_foo[[]1[]] SUBFAILED[[]custom[]] (i='1') *[[]100%[]]",
310+
"*.py::test_foo[[]1[]] SUBFAILED[[]custom[]] (i=1) *[[]100%[]]",
311311
"*.py::test_foo[[]1[]] FAILED *[[]100%[]]",
312312
"contains 1 failed subtest",
313313
"* 4 failed, 4 subtests passed in *",
@@ -323,9 +323,9 @@ def test_foo(subtests, x):
323323
result = pytester.runpytest("-v")
324324
result.stdout.fnmatch_lines(
325325
[
326-
"*.py::test_foo[[]0[]] SUBFAILED[[]custom[]] (i='1') *[[] 50%[]]",
326+
"*.py::test_foo[[]0[]] SUBFAILED[[]custom[]] (i=1) *[[] 50%[]]",
327327
"*.py::test_foo[[]0[]] FAILED *[[] 50%[]]",
328-
"*.py::test_foo[[]1[]] SUBFAILED[[]custom[]] (i='1') *[[]100%[]]",
328+
"*.py::test_foo[[]1[]] SUBFAILED[[]custom[]] (i=1) *[[]100%[]]",
329329
"*.py::test_foo[[]1[]] FAILED *[[]100%[]]",
330330
"contains 1 failed subtest",
331331
"* 4 failed in *",
@@ -710,12 +710,12 @@ def test_capturing(self, pytester: pytest.Pytester, mode: str) -> None:
710710
result = pytester.runpytest(f"--capture={mode}")
711711
result.stdout.fnmatch_lines(
712712
[
713-
"*__ test (i=\"'A'\") __*",
713+
"*__ test (i='A') __*",
714714
"*Captured stdout call*",
715715
"hello stdout A",
716716
"*Captured stderr call*",
717717
"hello stderr A",
718-
"*__ test (i=\"'B'\") __*",
718+
"*__ test (i='B') __*",
719719
"*Captured stdout call*",
720720
"hello stdout B",
721721
"*Captured stderr call*",
@@ -736,8 +736,8 @@ def test_no_capture(self, pytester: pytest.Pytester) -> None:
736736
"hello stdout A",
737737
"uhello stdout B",
738738
"uend test",
739-
"*__ test (i=\"'A'\") __*",
740-
"*__ test (i=\"'B'\") __*",
739+
"*__ test (i='A') __*",
740+
"*__ test (i='B') __*",
741741
"*__ test __*",
742742
]
743743
)

0 commit comments

Comments
 (0)