Skip to content

Commit 10a14d1

Browse files
bluetechpytestbot
authored andcommitted
[7.1.x] testing: fix tests when run under -v or -vv
1 parent 7d4d1ec commit 10a14d1

File tree

1 file changed

+9
-39
lines changed

1 file changed

+9
-39
lines changed

testing/test_assertrewrite.py

+9-39
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,8 @@ def f3() -> None:
204204
def f4() -> None:
205205
assert sys == 42 # type: ignore[comparison-overlap]
206206

207-
verbose = request.config.getoption("verbose")
208207
msg = getmsg(f4, {"sys": sys})
209-
if verbose > 0:
210-
assert msg == (
211-
"assert <module 'sys' (built-in)> == 42\n"
212-
" +<module 'sys' (built-in)>\n"
213-
" -42"
214-
)
215-
else:
216-
assert msg == "assert sys == 42"
208+
assert msg == "assert sys == 42"
217209

218210
def f5() -> None:
219211
assert cls == 42 # type: ignore[name-defined] # noqa: F821
@@ -224,20 +216,7 @@ class X:
224216
msg = getmsg(f5, {"cls": X})
225217
assert msg is not None
226218
lines = msg.splitlines()
227-
if verbose > 1:
228-
assert lines == [
229-
f"assert {X!r} == 42",
230-
f" +{X!r}",
231-
" -42",
232-
]
233-
elif verbose > 0:
234-
assert lines == [
235-
"assert <class 'test_...e.<locals>.X'> == 42",
236-
f" +{X!r}",
237-
" -42",
238-
]
239-
else:
240-
assert lines == ["assert cls == 42"]
219+
assert lines == ["assert cls == 42"]
241220

242221
def test_assertrepr_compare_same_width(self, request) -> None:
243222
"""Should use same width/truncation with same initial width."""
@@ -279,14 +258,11 @@ def f() -> None:
279258
msg = getmsg(f, {"cls": Y})
280259
assert msg is not None
281260
lines = msg.splitlines()
282-
if request.config.getoption("verbose") > 0:
283-
assert lines == ["assert 3 == 2", " +3", " -2"]
284-
else:
285-
assert lines == [
286-
"assert 3 == 2",
287-
" + where 3 = Y.foo",
288-
" + where Y = cls()",
289-
]
261+
assert lines == [
262+
"assert 3 == 2",
263+
" + where 3 = Y.foo",
264+
" + where Y = cls()",
265+
]
290266

291267
def test_assert_already_has_message(self) -> None:
292268
def f():
@@ -663,10 +639,7 @@ def f():
663639
assert len(values) == 11
664640

665641
msg = getmsg(f)
666-
if request.config.getoption("verbose") > 0:
667-
assert msg == "assert 10 == 11\n +10\n -11"
668-
else:
669-
assert msg == "assert 10 == 11\n + where 10 = len([0, 1, 2, 3, 4, 5, ...])"
642+
assert msg == "assert 10 == 11\n + where 10 = len([0, 1, 2, 3, 4, 5, ...])"
670643

671644
def test_custom_reprcompare(self, monkeypatch) -> None:
672645
def my_reprcompare1(op, left, right) -> str:
@@ -732,10 +705,7 @@ def __repr__(self):
732705
msg = getmsg(f)
733706
assert msg is not None
734707
lines = util._format_lines([msg])
735-
if request.config.getoption("verbose") > 0:
736-
assert lines == ["assert 0 == 1\n +0\n -1"]
737-
else:
738-
assert lines == ["assert 0 == 1\n + where 1 = \\n{ \\n~ \\n}.a"]
708+
assert lines == ["assert 0 == 1\n + where 1 = \\n{ \\n~ \\n}.a"]
739709

740710
def test_custom_repr_non_ascii(self) -> None:
741711
def f() -> None:

0 commit comments

Comments
 (0)