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 @@ -22,6 +22,7 @@ Internal
* Avoid depending on string matches into host info.
* Add more URL constants.
* Set `$VISUAL` whenever `$EDITOR` is set.
* Fix tempfile leak in test suite.


1.58.0 (2026/02/28)
Expand Down
15 changes: 10 additions & 5 deletions test/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import os
import shutil
import sys
from tempfile import mkstemp
from tempfile import NamedTemporaryFile

import db_utils as dbutils
import fixture_utils as fixutils
import pexpect

from steps.wrappers import run_cli, wait_prompt
from test.utils import TEMPFILE_PREFIX

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

Expand Down Expand Up @@ -65,13 +66,12 @@ def before_all(context):
"pager_boundary": "---boundary---",
}

_, my_cnf = mkstemp()
with open(my_cnf, "w") as f:
f.write(
with NamedTemporaryFile(prefix=TEMPFILE_PREFIX, mode='w', delete=False) as my_cnf:
my_cnf.write(
f'[client]\npager={sys.executable} '
f'{os.path.join(context.package_root, "test/features/wrappager.py")} {context.conf["pager_boundary"]}\n'
)
context.conf["defaults-file"] = my_cnf
context.conf["defaults-file"] = my_cnf.name
context.conf["myclirc"] = os.path.join(context.package_root, "test", "myclirc")

context.cn = dbutils.create_db(
Expand All @@ -85,6 +85,11 @@ def after_all(context):
"""Unset env parameters."""
dbutils.close_cn(context.cn)
dbutils.drop_db(context.conf["host"], context.conf["port"], context.conf["user"], context.conf["pass"], context.conf["dbname"])
try:
if os.path.exists(context.conf["defaults-file"]):
os.remove(context.conf["defaults-file"])
except Exception:
pass

# Restore env vars.
# for k, v in context.pgenv.items():
Expand Down
22 changes: 11 additions & 11 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import struct
import sys
import tempfile
from tempfile import NamedTemporaryFile

import pytest

Expand All @@ -18,6 +18,7 @@
str_to_bool,
strip_matching_quotes,
)
from test.utils import TEMPFILE_PREFIX

LOGIN_PATH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "mylogin.cnf"))

Expand Down Expand Up @@ -109,18 +110,17 @@ def test_get_mylogin_cnf_path(monkeypatch):
def test_alternate_get_mylogin_cnf_path(monkeypatch):
"""Tests that the alternate path for .mylogin.cnf is detected."""

fd, temp_path = tempfile.mkstemp()
monkeypatch.setenv('MYSQL_TEST_LOGIN_FILE', temp_path)

login_cnf_path = get_mylogin_cnf_path()

assert temp_path == login_cnf_path
with NamedTemporaryFile(prefix=TEMPFILE_PREFIX, mode='w', delete=False) as login_file:
monkeypatch.setenv('MYSQL_TEST_LOGIN_FILE', login_file.name)
login_cnf_path = get_mylogin_cnf_path()

try:
os.close(fd)
os.remove(temp_path)
except Exception:
pass
assert login_file.name == login_cnf_path
except AssertionError as e:
assert AssertionError(e)
finally:
if os.path.exists(login_file.name):
os.remove(login_file.name)


def test_str_to_bool():
Expand Down