summaryrefslogtreecommitdiff
path: root/tests/test_completion.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-03-21 17:40:41 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-03-21 17:40:41 -0400
commita1c72448cff540c9d6e610f3973a70cf495aadb6 (patch)
treeb0119c62cf1f480f1c6bbc7fcaffc9767f78db2d /tests/test_completion.py
parent4cea62a8fb7f5da3cfd4ee32fde831f401c128dc (diff)
downloadcmd2-git-a1c72448cff540c9d6e610f3973a70cf495aadb6.tar.gz
Fix unit tests on macOS when gnureadline is installed
As similar try/except needed to be added to a couple unit test files to try to import gnureadline as readline and fallback to importing readline.
Diffstat (limited to 'tests/test_completion.py')
-rw-r--r--tests/test_completion.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py
index f749f084..35d014cd 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -10,7 +10,6 @@ Released under MIT license, see LICENSE file
"""
import argparse
import os
-import readline
import sys
import cmd2
@@ -19,6 +18,19 @@ import pytest
from cmd2 import path_complete, basic_complete, flag_based_complete, index_based_complete
+# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
+try:
+ import gnureadline as readline
+except ImportError:
+ # Try to import readline, but allow failure for convenience in Windows unit testing
+ # Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows
+ try:
+ # noinspection PyUnresolvedReferences
+ import readline
+ except ImportError:
+ pass
+
+
@pytest.fixture
def cmd2_app():
c = cmd2.Cmd()