Skip to content

Commit 91ece5e

Browse files
committed
tests: handle new output format with Python 3.8
Fixes #139.
1 parent 4e249da commit 91ece5e

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

test_pytest_mock.py

+29-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
platform.python_implementation() == "PyPy", reason="could not make work on pypy"
1414
)
1515

16+
# Python 3.8 changed the output formatting (bpo-35500).
17+
PY38 = sys.version_info >= (3, 8)
18+
1619

1720
@pytest.fixture
1821
def needs_assert_rewrite(pytestconfig):
@@ -194,7 +197,11 @@ def test_repr_with_name(self, mocker):
194197

195198
def __test_failure_message(self, mocker, **kwargs):
196199
expected_name = kwargs.get("name") or "mock"
197-
expected_message = "Expected call: {0}()\nNot called".format(expected_name)
200+
if PY38:
201+
msg = "expected call not found.\nExpected: {0}()\nActual: not called."
202+
else:
203+
msg = "Expected call: {0}()\nNot called"
204+
expected_message = msg.format(expected_name)
198205
stub = mocker.stub(**kwargs)
199206
with pytest.raises(AssertionError) as exc_info:
200207
stub.assert_called_with()
@@ -585,22 +592,30 @@ def test(mocker):
585592
"""
586593
)
587594
result = testdir.runpytest("-s")
588-
result.stdout.fnmatch_lines(
589-
[
595+
if PY38:
596+
expected_lines = [
597+
"*AssertionError: expected call not found.",
598+
"*Expected: mock('', bar=4)",
599+
"*Actual: mock('fo')",
600+
]
601+
else:
602+
expected_lines = [
590603
"*AssertionError: Expected call: mock('', bar=4)*",
591604
"*Actual call: mock('fo')*",
592-
"*pytest introspection follows:*",
593-
"*Args:",
594-
"*assert ('fo',) == ('',)",
595-
"*At index 0 diff: 'fo' != ''*",
596-
"*Use -v to get the full diff*",
597-
"*Kwargs:*",
598-
"*assert {} == {'bar': 4}*",
599-
"*Right contains more items:*",
600-
"*{'bar': 4}*",
601-
"*Use -v to get the full diff*",
602605
]
603-
)
606+
expected_lines += [
607+
"*pytest introspection follows:*",
608+
"*Args:",
609+
"*assert ('fo',) == ('',)",
610+
"*At index 0 diff: 'fo' != ''*",
611+
"*Use -v to get the full diff*",
612+
"*Kwargs:*",
613+
"*assert {} == {'bar': 4}*",
614+
"*Right contains more items:*",
615+
"*{'bar': 4}*",
616+
"*Use -v to get the full diff*",
617+
]
618+
result.stdout.fnmatch_lines(expected_lines)
604619

605620

606621
def test_assert_called_with_unicode_arguments(mocker):

0 commit comments

Comments
 (0)