@@ -339,7 +339,7 @@ def assert_traceback():
339
339
340
340
341
341
@contextmanager
342
- def assert_argument_introspection (left , right ):
342
+ def assert_argument_introspection (arg_left , arg_right , kwarg_left , kwarg_right ):
343
343
"""
344
344
Assert detailed argument introspection is used
345
345
"""
@@ -351,7 +351,8 @@ def assert_argument_introspection(left, right):
351
351
# NOTE: we assert with either verbose or not, depending on how our own
352
352
# test was run by examining sys.argv
353
353
verbose = any (a .startswith ('-v' ) for a in sys .argv )
354
- expected = '\n ' .join (util ._compare_eq_iterable (left , right , verbose ))
354
+ expected = '\n ' .join (util ._compare_eq_iterable (
355
+ (arg_left , kwarg_left ), (arg_right , kwarg_right ), verbose ))
355
356
assert expected in e .msg
356
357
else :
357
358
raise AssertionError ("DID NOT RAISE" )
@@ -394,7 +395,7 @@ def test_assert_called_args_with_introspection(mocker):
394
395
stub .assert_called_with (* complex_args )
395
396
stub .assert_called_once_with (* complex_args )
396
397
397
- with assert_argument_introspection (complex_args , wrong_args ):
398
+ with assert_argument_introspection (wrong_args , complex_args , {}, {} ):
398
399
stub .assert_called_with (* wrong_args )
399
400
stub .assert_called_once_with (* wrong_args )
400
401
@@ -409,7 +410,7 @@ def test_assert_called_kwargs_with_introspection(mocker):
409
410
stub .assert_called_with (** complex_kwargs )
410
411
stub .assert_called_once_with (** complex_kwargs )
411
412
412
- with assert_argument_introspection (complex_kwargs , wrong_kwargs ):
413
+ with assert_argument_introspection ((), (), wrong_kwargs , complex_kwargs ):
413
414
stub .assert_called_with (** wrong_kwargs )
414
415
stub .assert_called_once_with (** wrong_kwargs )
415
416
@@ -500,12 +501,12 @@ def test_foo(mocker):
500
501
assert len (traceback_lines ) == 1 # make sure there are no duplicated tracebacks (#44)
501
502
502
503
503
- def test_assertion_error_is_not_descriptive (mocker ):
504
- """Demonstrate that assert_wrapper does really bad things to assertion messages """
504
+ def test_assertion_error_is_descriptive (mocker ):
505
+ """Verify assert_wrapper starts with original call comparison error msg """
505
506
import mock
506
507
from pytest_mock import _mock_module_originals
507
508
mocker_mock = mocker .patch ('os.remove' )
508
- mock_mock = mock .Mock ()
509
+ mock_mock = mock .patch ( 'os.remove' ). start () # use same func name
509
510
assert_called_with = _mock_module_originals ['assert_called_with' ]
510
511
511
512
mocker_mock (a = 1 , b = 2 )
@@ -521,4 +522,4 @@ def test_assertion_error_is_not_descriptive(mocker):
521
522
except AssertionError as e :
522
523
mock_error_message = e .msg
523
524
524
- assert mock_error_message == mocker_error_message
525
+ assert mocker_error_message . startswith ( mock_error_message )
0 commit comments