File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -75,16 +75,20 @@ def test_version(base_app):
7575 assert cmd2 .__version__
7676
7777
78- @pytest .mark .skipif (sys .version_info >= (3 , 8 ), reason = "failing in CI systems for Python 3.8 and 3.9" )
7978def test_not_in_main_thread (base_app , capsys ):
8079 import threading
8180
82- cli_thread = threading .Thread (name = 'cli_thread' , target = base_app .cmdloop )
81+ # Mock threading.main_thread() to return our fake thread
82+ saved_main_thread = threading .main_thread
83+ fake_main = threading .Thread ()
84+ threading .main_thread = mock .MagicMock (name = 'main_thread' , return_value = fake_main )
8385
84- cli_thread .start ()
85- cli_thread .join ()
86- out , err = capsys .readouterr ()
87- assert "cmdloop must be run in the main thread" in err
86+ with pytest .raises (RuntimeError ) as excinfo :
87+ base_app .cmdloop ()
88+
89+ # Restore threading.main_thread()
90+ threading .main_thread = saved_main_thread
91+ assert "cmdloop must be run in the main thread" in str (excinfo .value )
8892
8993
9094def test_empty_statement (base_app ):
You can’t perform that action at this time.
0 commit comments