14
14
)
15
15
16
16
# Python 3.8 changed the output formatting (bpo-35500), which has been ported to mock 3.0
17
- NEW_FORMATTING = sys .version_info >= (3 , 8 ) or sys . version_info [ 0 ] == 2
17
+ NEW_FORMATTING = sys .version_info >= (3 , 8 )
18
18
19
19
20
20
@pytest .fixture
@@ -32,7 +32,7 @@ def needs_assert_rewrite(pytestconfig):
32
32
)
33
33
34
34
35
- class UnixFS ( object ) :
35
+ class UnixFS :
36
36
"""
37
37
Wrapper to os functions to simulate a Unix file system, used for testing
38
38
the mock fixture.
@@ -183,7 +183,7 @@ def test_repr_with_no_name(self, mocker):
183
183
def test_repr_with_name (self , mocker ):
184
184
test_name = "funny walk"
185
185
stub = mocker .stub (name = test_name )
186
- assert "name={0 !r}" .format (test_name ) in repr (stub )
186
+ assert "name={!r}" .format (test_name ) in repr (stub )
187
187
188
188
def __test_failure_message (self , mocker , ** kwargs ):
189
189
expected_name = kwargs .get ("name" ) or "mock"
@@ -206,7 +206,7 @@ def test_failure_message_with_name(self, mocker, name):
206
206
207
207
208
208
def test_instance_method_spy (mocker ):
209
- class Foo ( object ) :
209
+ class Foo :
210
210
def bar (self , arg ):
211
211
return arg * 2
212
212
@@ -222,7 +222,7 @@ def bar(self, arg):
222
222
223
223
224
224
def test_instance_method_spy_exception (mocker ):
225
- class Foo ( object ) :
225
+ class Foo :
226
226
def bar (self , arg ):
227
227
raise Exception ("Error with {}" .format (arg ))
228
228
@@ -266,7 +266,7 @@ def bar(self, x):
266
266
267
267
@skip_pypy
268
268
def test_instance_method_by_class_spy (mocker ):
269
- class Foo ( object ) :
269
+ class Foo :
270
270
def bar (self , arg ):
271
271
return arg * 2
272
272
@@ -281,7 +281,7 @@ def bar(self, arg):
281
281
282
282
@skip_pypy
283
283
def test_instance_method_by_subclass_spy (mocker ):
284
- class Base ( object ) :
284
+ class Base :
285
285
def bar (self , arg ):
286
286
return arg * 2
287
287
@@ -300,7 +300,7 @@ class Foo(Base):
300
300
301
301
@skip_pypy
302
302
def test_class_method_spy (mocker ):
303
- class Foo ( object ) :
303
+ class Foo :
304
304
@classmethod
305
305
def bar (cls , arg ):
306
306
return arg * 2
@@ -314,9 +314,8 @@ def bar(cls, arg):
314
314
315
315
316
316
@skip_pypy
317
- @pytest .mark .xfail (sys .version_info [0 ] == 2 , reason = "does not work on Python 2" )
318
317
def test_class_method_subclass_spy (mocker ):
319
- class Base ( object ) :
318
+ class Base :
320
319
@classmethod
321
320
def bar (self , arg ):
322
321
return arg * 2
@@ -337,7 +336,7 @@ def test_class_method_with_metaclass_spy(mocker):
337
336
class MetaFoo (type ):
338
337
pass
339
338
340
- class Foo ( object ) :
339
+ class Foo :
341
340
342
341
__metaclass__ = MetaFoo
343
342
@@ -355,7 +354,7 @@ def bar(cls, arg):
355
354
356
355
@skip_pypy
357
356
def test_static_method_spy (mocker ):
358
- class Foo ( object ) :
357
+ class Foo :
359
358
@staticmethod
360
359
def bar (arg ):
361
360
return arg * 2
@@ -369,9 +368,8 @@ def bar(arg):
369
368
370
369
371
370
@skip_pypy
372
- @pytest .mark .xfail (sys .version_info [0 ] == 2 , reason = "does not work on Python 2" )
373
371
def test_static_method_subclass_spy (mocker ):
374
- class Base ( object ) :
372
+ class Base :
375
373
@staticmethod
376
374
def bar (arg ):
377
375
return arg * 2
@@ -442,10 +440,6 @@ def assert_argument_introspection(left, right):
442
440
raise AssertionError ("DID NOT RAISE" )
443
441
444
442
445
- @pytest .mark .skipif (
446
- sys .version_info [:2 ] == (3 , 4 ),
447
- reason = "assert_not_called not available in Python 3.4" ,
448
- )
449
443
def test_assert_not_called_wrapper (mocker ):
450
444
stub = mocker .stub ()
451
445
stub .assert_not_called ()
@@ -498,8 +492,8 @@ def test_assert_called_wrapper(mocker):
498
492
def test_assert_called_args_with_introspection (mocker ):
499
493
stub = mocker .stub ()
500
494
501
- complex_args = ("a" , 1 , set ([ "test" ]) )
502
- wrong_args = ("b" , 2 , set ([ "jest" ]) )
495
+ complex_args = ("a" , 1 , { "test" } )
496
+ wrong_args = ("b" , 2 , { "jest" } )
503
497
504
498
stub (* complex_args )
505
499
stub .assert_called_with (* complex_args )
@@ -631,7 +625,6 @@ def test_foo(mocker):
631
625
assert result .stdout .lines == []
632
626
633
627
634
- @pytest .mark .skipif (sys .version_info [0 ] < 3 , reason = "Py3 only" )
635
628
def test_standalone_mock (testdir ):
636
629
"""Check that the "mock_use_standalone" is being used.
637
630
"""
@@ -720,7 +713,7 @@ def test_assert_called_with_unicode_arguments(mocker):
720
713
stub (b"l\xc3 \xb6 k" .decode ("UTF-8" ))
721
714
722
715
with pytest .raises (AssertionError ):
723
- stub .assert_called_with (u "lak" )
716
+ stub .assert_called_with ("lak" )
724
717
725
718
726
719
def test_plain_stopall (testdir ):
@@ -745,15 +738,15 @@ def test_get_random_number(mocker):
745
738
746
739
747
740
def test_abort_patch_object_context_manager (mocker ):
748
- class A ( object ) :
741
+ class A :
749
742
def doIt (self ):
750
743
return False
751
744
752
745
a = A ()
753
746
754
747
with pytest .raises (ValueError ) as excinfo :
755
748
with mocker .patch .object (a , "doIt" , return_value = True ):
756
- assert a .doIt () == True
749
+ assert a .doIt () is True
757
750
758
751
expected_error_msg = (
759
752
"Using mocker in a with context is not supported. "
@@ -803,7 +796,7 @@ def test_foo(mocker):
803
796
result = testdir .runpytest ()
804
797
result .stdout .fnmatch_lines ("* 1 passed *" )
805
798
806
- kwargs = {"legacy" : True } if sys . version_info [ 0 ] >= 3 else {}
799
+ kwargs = {"legacy" : True }
807
800
assert compileall .compile_file (str (py_fn ), ** kwargs )
808
801
809
802
pyc_fn = str (py_fn ) + "c"
0 commit comments