Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Features
Internal
---------
* Add Trove classifiers for PyPi.
* Don't let behave tests refer to real home-directory resources.


2.7.0 (2026/07/25)
Expand Down
22 changes: 4 additions & 18 deletions test/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
from mycli.constants import DEFAULT_HOST, DEFAULT_PORT, DEFAULT_USER
from steps.wrappers import run_cli, wait_prompt

test_log_file = os.path.join(os.environ["HOME"], ".mycli.test.log")

fd, TEST_LOG_FILE = tempfile.mkstemp(prefix='mycli-behave-', suffix='.test.log')
os.close(fd)

SELF_CONNECTING_FEATURES = ("test/features/connection.feature",)


MYLOGIN_CNF_PATH = os.path.expanduser("~/.mylogin.cnf")
MYLOGIN_CNF_BACKUP_PATH = f"{MYLOGIN_CNF_PATH}.backup"


def get_db_name_from_context(context):
return context.config.userdata.get("my_test_db", None) or "mycli_behave_tests"

Expand Down Expand Up @@ -111,19 +107,16 @@ def before_scenario(context, arg):
# Skip flaky editor test in CI
if os.getenv('GITHUB_ACTION') and 'skip_ci' in arg.tags:
arg.skip('Skipped in CI')
with open(test_log_file, "w") as f:
with open(TEST_LOG_FILE, "w") as f:
f.write("")
if arg.location.filename not in SELF_CONNECTING_FEATURES:
run_cli(context)
wait_prompt(context)

if os.path.exists(MYLOGIN_CNF_PATH):
shutil.move(MYLOGIN_CNF_PATH, MYLOGIN_CNF_BACKUP_PATH)


def after_scenario(context, _):
"""Cleans up after each test complete."""
with open(test_log_file) as f:
with open(TEST_LOG_FILE) as f:
for line in f:
if "error" in line.lower():
raise RuntimeError(f"Error in log file: {line}")
Expand All @@ -139,13 +132,6 @@ def after_scenario(context, _):
context.cli.sendcontrol("d")
context.cli.expect_exact(pexpect.EOF, timeout=5)

if os.path.exists(MYLOGIN_CNF_BACKUP_PATH):
shutil.move(MYLOGIN_CNF_BACKUP_PATH, MYLOGIN_CNF_PATH)
elif os.path.exists(MYLOGIN_CNF_PATH):
# This file was moved in `before_scenario`.
# If it exists now, it has been created during a test
os.remove(MYLOGIN_CNF_PATH)


# TODO: uncomment to debug a failure
# def after_step(context, step):
Expand Down
Loading