|
13 | 13 | platform.python_implementation() == "PyPy", reason="could not make work on pypy"
|
14 | 14 | )
|
15 | 15 |
|
| 16 | +# Python 3.8 changed the output formatting (bpo-35500). |
| 17 | +PY38 = sys.version_info >= (3, 8) |
| 18 | + |
16 | 19 |
|
17 | 20 | @pytest.fixture
|
18 | 21 | def needs_assert_rewrite(pytestconfig):
|
@@ -194,7 +197,11 @@ def test_repr_with_name(self, mocker):
|
194 | 197 |
|
195 | 198 | def __test_failure_message(self, mocker, **kwargs):
|
196 | 199 | 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) |
198 | 205 | stub = mocker.stub(**kwargs)
|
199 | 206 | with pytest.raises(AssertionError) as exc_info:
|
200 | 207 | stub.assert_called_with()
|
@@ -585,22 +592,30 @@ def test(mocker):
|
585 | 592 | """
|
586 | 593 | )
|
587 | 594 | 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 = [ |
590 | 603 | "*AssertionError: Expected call: mock('', bar=4)*",
|
591 | 604 | "*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*", |
602 | 605 | ]
|
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) |
604 | 619 |
|
605 | 620 |
|
606 | 621 | def test_assert_called_with_unicode_arguments(mocker):
|
|
0 commit comments