Skip to content

Commit f24fe11

Browse files
committed
Fixed unit test for Python 3.8+ systems.
1 parent 65cdf34 commit f24fe11

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tests/test_cmd2.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff 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")
7978
def 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

9094
def test_empty_statement(base_app):

0 commit comments

Comments
 (0)