Skip to content

Commit afabbb6

Browse files
authored
minor: test_assertion: improve mock_config (#5940)
minor: test_assertion: improve mock_config
2 parents db6653c + fb90259 commit afabbb6

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

testing/test_assertion.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
from _pytest.compat import ATTRS_EQ_FIELD
1313

1414

15-
def mock_config():
15+
def mock_config(verbose=0):
1616
class Config:
17-
verbose = False
18-
1917
def getoption(self, name):
2018
if name == "verbose":
21-
return self.verbose
19+
return verbose
2220
raise KeyError("Not mocked out: %s" % name)
2321

2422
return Config()
@@ -296,9 +294,8 @@ def test_check(list):
296294
result.stdout.fnmatch_lines(["*test_hello*FAIL*", "*test_check*PASS*"])
297295

298296

299-
def callequal(left, right, verbose=False):
300-
config = mock_config()
301-
config.verbose = verbose
297+
def callequal(left, right, verbose=0):
298+
config = mock_config(verbose=verbose)
302299
return plugin.pytest_assertrepr_compare(config, "==", left, right)
303300

304301

@@ -322,7 +319,7 @@ def test_text_skipping(self):
322319
assert "a" * 50 not in line
323320

324321
def test_text_skipping_verbose(self):
325-
lines = callequal("a" * 50 + "spam", "a" * 50 + "eggs", verbose=True)
322+
lines = callequal("a" * 50 + "spam", "a" * 50 + "eggs", verbose=1)
326323
assert "- " + "a" * 50 + "spam" in lines
327324
assert "+ " + "a" * 50 + "eggs" in lines
328325

@@ -345,7 +342,7 @@ def test_bytes_diff_normal(self):
345342

346343
def test_bytes_diff_verbose(self):
347344
"""Check special handling for bytes diff (#5260)"""
348-
diff = callequal(b"spam", b"eggs", verbose=True)
345+
diff = callequal(b"spam", b"eggs", verbose=1)
349346
assert diff == [
350347
"b'spam' == b'eggs'",
351348
"At index 0 diff: b's' != b'e'",
@@ -402,9 +399,9 @@ def test_iterable_full_diff(self, left, right, expected):
402399
When verbose is False, then just a -v notice to get the diff is rendered,
403400
when verbose is True, then ndiff of the pprint is returned.
404401
"""
405-
expl = callequal(left, right, verbose=False)
402+
expl = callequal(left, right, verbose=0)
406403
assert expl[-1] == "Use -v to get the full diff"
407-
expl = "\n".join(callequal(left, right, verbose=True))
404+
expl = "\n".join(callequal(left, right, verbose=1))
408405
assert expl.endswith(textwrap.dedent(expected).strip())
409406

410407
def test_list_different_lengths(self):

0 commit comments

Comments
 (0)