Skip to content

Commit

Permalink
Fixed unit test for Python 3.8+ systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Sep 13, 2024
1 parent 65cdf34 commit f24fe11
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,20 @@ def test_version(base_app):
assert cmd2.__version__


@pytest.mark.skipif(sys.version_info >= (3, 8), reason="failing in CI systems for Python 3.8 and 3.9")
def test_not_in_main_thread(base_app, capsys):
import threading

cli_thread = threading.Thread(name='cli_thread', target=base_app.cmdloop)
# Mock threading.main_thread() to return our fake thread
saved_main_thread = threading.main_thread
fake_main = threading.Thread()
threading.main_thread = mock.MagicMock(name='main_thread', return_value=fake_main)

cli_thread.start()
cli_thread.join()
out, err = capsys.readouterr()
assert "cmdloop must be run in the main thread" in err
with pytest.raises(RuntimeError) as excinfo:
base_app.cmdloop()

# Restore threading.main_thread()
threading.main_thread = saved_main_thread
assert "cmdloop must be run in the main thread" in str(excinfo.value)


def test_empty_statement(base_app):
Expand Down

0 comments on commit f24fe11

Please sign in to comment.