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 ):
@@ -185,7 +188,7 @@ def test_call(self, mocker):
185
188
186
189
def test_repr_with_no_name (self , mocker ):
187
190
stub = mocker .stub ()
188
- assert not "name" in repr (stub )
191
+ assert "name" not in repr (stub )
189
192
190
193
def test_repr_with_name (self , mocker ):
191
194
test_name = "funny walk"
@@ -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}()\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 )
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 ):
@@ -613,7 +628,7 @@ def test_assert_called_with_unicode_arguments(mocker):
613
628
614
629
615
630
def 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)"""
617
632
testdir .makepyfile (
618
633
"""
619
634
import random
0 commit comments