11"""Unit/functional testing for run_pytest in cmd2"""
22
3- import builtins
43import os
54from unittest import (
65 mock ,
@@ -43,9 +42,10 @@ def test_run_pyscript_with_nonexist_file(base_app) -> None:
4342 assert base_app .last_result is False
4443
4544
46- def test_run_pyscript_with_non_python_file (base_app , request ) -> None :
47- m = mock .MagicMock (name = 'input' , return_value = '2' )
48- builtins .input = m
45+ def test_run_pyscript_with_non_python_file (base_app , request , monkeypatch ) -> None :
46+ # Mock out the read_input call so we don't actually wait for a user's response on stdin
47+ read_input_mock = mock .MagicMock (name = 'read_input' , return_value = '2' )
48+ monkeypatch .setattr ("cmd2.Cmd.read_input" , read_input_mock )
4949
5050 test_dir = os .path .dirname (request .module .__file__ )
5151 filename = os .path .join (test_dir , 'scripts' , 'help.txt' )
@@ -55,13 +55,13 @@ def test_run_pyscript_with_non_python_file(base_app, request) -> None:
5555
5656
5757@pytest .mark .parametrize ('python_script' , odd_file_names )
58- def test_run_pyscript_with_odd_file_names (base_app , python_script ) -> None :
58+ def test_run_pyscript_with_odd_file_names (base_app , python_script , monkeypatch ) -> None :
5959 """Pass in file names with various patterns. Since these files don't exist, we will rely
6060 on the error text to make sure the file names were processed correctly.
6161 """
62- # Mock input to get us passed the warning about not ending in .py
63- input_mock = mock .MagicMock (name = 'input ' , return_value = '1' )
64- builtins . input = input_mock
62+ # Mock read_input to get us passed the warning about not ending in .py
63+ read_input_mock = mock .MagicMock (name = 'read_input ' , return_value = '1' )
64+ monkeypatch . setattr ( "cmd2.Cmd.read_input" , read_input_mock )
6565
6666 _out , err = run_cmd (base_app , f"run_pyscript { quote (python_script )} " )
6767 err = '' .join (err )
0 commit comments