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):
75
75
assert cmd2 .__version__
76
76
77
77
78
- @pytest .mark .skipif (sys .version_info >= (3 , 8 ), reason = "failing in CI systems for Python 3.8 and 3.9" )
79
78
def test_not_in_main_thread (base_app , capsys ):
80
79
import threading
81
80
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 )
83
85
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 )
88
92
89
93
90
94
def test_empty_statement (base_app ):
You can’t perform that action at this time.
0 commit comments