diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-07-09 13:00:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-09 13:00:08 -0400 |
commit | ba057d8d1250d847417075645806d2d721386873 (patch) | |
tree | 8097fc52f8c1acde6cd7e580d054c05d0d06c4c7 /tests/test_cmd2.py | |
parent | c37ba6f32f76b151b9ffc279ddc22af913336847 (diff) | |
parent | 87e04d73046e910b639aaec462b4b77a1735f404 (diff) | |
download | cmd2-git-ba057d8d1250d847417075645806d2d721386873.tar.gz |
Merge pull request #182 from felixonmars/fix-test
Use monkeypatch to ensure os.system is restored
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 1deff479..0e25529a 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -661,13 +661,13 @@ def test_edit_no_editor(base_app, capsys): expected = _expected_no_editor_error() assert normalize(str(err)) == expected -def test_edit_file(base_app, request): +def test_edit_file(base_app, request, monkeypatch): # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock base_app.editor = 'fooedit' # Mock out the os.system call so we don't actually open an editor m = mock.MagicMock(name='system') - os.system = m + monkeypatch.setattr("os.system", m) test_dir = os.path.dirname(request.module.__file__) filename = os.path.join(test_dir, 'script.txt') @@ -677,13 +677,13 @@ def test_edit_file(base_app, request): # We think we have an editor, so should expect a system call m.assert_called_once_with('{} {}'.format(base_app.editor, filename)) -def test_edit_number(base_app): +def test_edit_number(base_app, monkeypatch): # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock base_app.editor = 'fooedit' # Mock out the os.system call so we don't actually open an editor m = mock.MagicMock(name='system') - os.system = m + monkeypatch.setattr("os.system", m) # Run help command just so we have a command in history run_cmd(base_app, 'help') @@ -693,13 +693,13 @@ def test_edit_number(base_app): # We have an editor, so should expect a system call m.assert_called_once() -def test_edit_blank(base_app): +def test_edit_blank(base_app, monkeypatch): # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock base_app.editor = 'fooedit' # Mock out the os.system call so we don't actually open an editor m = mock.MagicMock(name='system') - os.system = m + monkeypatch.setattr("os.system", m) # Run help command just so we have a command in history run_cmd(base_app, 'help') @@ -1222,7 +1222,7 @@ def abbrev_app(): app.stdout = StdOut() return app -def test_exclude_from_history(abbrev_app): +def test_exclude_from_history(abbrev_app, monkeypatch): # Run all variants of run run_cmd(abbrev_app, 'run') run_cmd(abbrev_app, 'ru') @@ -1230,7 +1230,7 @@ def test_exclude_from_history(abbrev_app): # Mock out the os.system call so we don't actually open an editor m = mock.MagicMock(name='system') - os.system = m + monkeypatch.setattr("os.system", m) # Run all variants of edit run_cmd(abbrev_app, 'edit') |