@@ -406,26 +406,21 @@ def test_history_output_file(base_app):
406406 content = normalize (f .read ())
407407 assert content == expected
408408
409- def test_history_edit (base_app , mock ):
409+ def test_history_edit (base_app , monkeypatch ):
410410 # Set a fake editor just to make sure we have one. We aren't really
411411 # going to call it due to the mock
412412 base_app .editor = 'fooedit'
413413
414414 # Mock out the os.system call so we don't actually open an editor
415- count = [0 ]
416-
417- def fake_system (* args , ** kwargs ):
418- count [0 ] += 1
419-
420- mock .patch .object (os , 'system' , fake_system )
415+ m = mock .MagicMock (name = 'system' )
416+ monkeypatch .setattr ("os.system" , m )
421417
422418 # Run help command just so we have a command in history
423419 run_cmd (base_app , 'help' )
424420 run_cmd (base_app , 'history -e 1' )
425421
426422 # We have an editor, so should expect a system call
427- assert count [0 ] == 1
428-
423+ m .assert_called_once ()
429424
430425def test_history_run_all_commands (base_app ):
431426 # make sure we refuse to run all commands as a default
@@ -824,36 +819,29 @@ def test_edit_file_with_spaces(base_app, request, monkeypatch):
824819 # We think we have an editor, so should expect a system call
825820 m .assert_called_once_with ('"{}" "{}"' .format (base_app .editor , filename ))
826821
827- def test_edit_blank (base_app , mock ):
822+ def test_edit_blank (base_app , monkeypatch ):
828823 # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
829824 base_app .editor = 'fooedit'
830825
831- count = [0 ]
832-
833- def fake_system (* args , ** kwargs ):
834- count [0 ] += 1
835-
836- mock .patch .object (os , 'system' , fake_system )
826+ # Mock out the os.system call so we don't actually open an editor
827+ m = mock .MagicMock (name = 'system' )
828+ monkeypatch .setattr ("os.system" , m )
837829
838830 run_cmd (base_app , 'edit' )
839831
840832 # We have an editor, so should expect a system call
841- assert count [ 0 ] == 1
833+ m . assert_called_once ()
842834
843835
844- def test_base_py_interactive (base_app , mock ):
836+ def test_base_py_interactive (base_app ):
845837 # Mock out the InteractiveConsole.interact() call so we don't actually wait for a user's response on stdin
846- count = [0 ]
847-
848- def fake_interact (* args , ** kwargs ):
849- count [0 ] += 1
850-
851- mock .patch .object (InteractiveConsole , 'interact' , fake_interact )
838+ m = mock .MagicMock (name = 'interact' )
839+ InteractiveConsole .interact = m
852840
853841 run_cmd (base_app , "py" )
854842
855843 # Make sure our mock was called once and only once
856- assert count [ 0 ] == 1
844+ m . assert_called_once ()
857845
858846
859847def test_exclude_from_history (base_app , monkeypatch ):
0 commit comments