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
1821def needs_assert_rewrite (pytestconfig ):
@@ -185,7 +188,7 @@ def test_call(self, mocker):
185188
186189 def test_repr_with_no_name (self , mocker ):
187190 stub = mocker .stub ()
188- assert not "name" in repr (stub )
191+ assert "name" not in repr (stub )
189192
190193 def test_repr_with_name (self , mocker ):
191194 test_name = "funny walk"
@@ -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}()\n Not called" .format (expected_name )
200+ if PY38 :
201+ msg = "expected call not found.\n Expected: {0}()\n Actual: not called."
202+ else :
203+ msg = "Expected call: {0}()\n Not 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
606621def test_assert_called_with_unicode_arguments (mocker ):
@@ -613,7 +628,7 @@ def test_assert_called_with_unicode_arguments(mocker):
613628
614629
615630def test_plain_stopall (testdir ):
616- """Calling patch.stopall() in a test would cause an error during unconfigure (#137)"""
631+ """patch.stopall() in a test should not cause an error during unconfigure (#137)"""
617632 testdir .makepyfile (
618633 """
619634 import random
0 commit comments