Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.1.x] testing: fix tests when run under -v or -vv #9784

Merged
merged 2 commits into from Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions extra/setup-py.test/setup.py
@@ -1,4 +1,5 @@
import sys

from distutils.core import setup

if __name__ == "__main__":
Expand Down
48 changes: 9 additions & 39 deletions testing/test_assertrewrite.py
Expand Up @@ -204,16 +204,8 @@ def f3() -> None:
def f4() -> None:
assert sys == 42 # type: ignore[comparison-overlap]

verbose = request.config.getoption("verbose")
msg = getmsg(f4, {"sys": sys})
if verbose > 0:
assert msg == (
"assert <module 'sys' (built-in)> == 42\n"
" +<module 'sys' (built-in)>\n"
" -42"
)
else:
assert msg == "assert sys == 42"
assert msg == "assert sys == 42"

def f5() -> None:
assert cls == 42 # type: ignore[name-defined] # noqa: F821
Expand All @@ -224,20 +216,7 @@ class X:
msg = getmsg(f5, {"cls": X})
assert msg is not None
lines = msg.splitlines()
if verbose > 1:
assert lines == [
f"assert {X!r} == 42",
f" +{X!r}",
" -42",
]
elif verbose > 0:
assert lines == [
"assert <class 'test_...e.<locals>.X'> == 42",
f" +{X!r}",
" -42",
]
else:
assert lines == ["assert cls == 42"]
assert lines == ["assert cls == 42"]

def test_assertrepr_compare_same_width(self, request) -> None:
"""Should use same width/truncation with same initial width."""
Expand Down Expand Up @@ -279,14 +258,11 @@ def f() -> None:
msg = getmsg(f, {"cls": Y})
assert msg is not None
lines = msg.splitlines()
if request.config.getoption("verbose") > 0:
assert lines == ["assert 3 == 2", " +3", " -2"]
else:
assert lines == [
"assert 3 == 2",
" + where 3 = Y.foo",
" + where Y = cls()",
]
assert lines == [
"assert 3 == 2",
" + where 3 = Y.foo",
" + where Y = cls()",
]

def test_assert_already_has_message(self) -> None:
def f():
Expand Down Expand Up @@ -663,10 +639,7 @@ def f():
assert len(values) == 11

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

def test_custom_reprcompare(self, monkeypatch) -> None:
def my_reprcompare1(op, left, right) -> str:
Expand Down Expand Up @@ -732,10 +705,7 @@ def __repr__(self):
msg = getmsg(f)
assert msg is not None
lines = util._format_lines([msg])
if request.config.getoption("verbose") > 0:
assert lines == ["assert 0 == 1\n +0\n -1"]
else:
assert lines == ["assert 0 == 1\n + where 1 = \\n{ \\n~ \\n}.a"]
assert lines == ["assert 0 == 1\n + where 1 = \\n{ \\n~ \\n}.a"]

def test_custom_repr_non_ascii(self) -> None:
def f() -> None:
Expand Down