Skip to content

Commit 3025a1f

Browse files
committed
Fix mysql_defaults_file fixture
1 parent 62d95a7 commit 3025a1f

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

pytest_services/mysql.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Fixtures for mysql."""
22
import os
33
import shutil
4+
from textwrap import dedent
45

5-
from distutils.spawn import find_executable # pylint: disable=E0611
66
import pytest
77

88
from .process import (
@@ -16,22 +16,28 @@ def mysql_defaults_file(
1616
run_services, tmp_path_factory, memory_temp_dir, request):
1717
"""MySQL defaults file."""
1818
if run_services:
19-
cfg = tmp_path_factory.mktemp(request.session.name)
19+
cfg = tmp_path_factory.mktemp("pytest-services")
2020
defaults_path = str(cfg / 'defaults.cnf')
2121

2222
with open(defaults_path, 'w+') as fd:
23-
fd.write("""
24-
[mysqld]
25-
user = {user}
26-
tmpdir = {tmpdir}
27-
default-time-zone = SYSTEM
28-
""".format(user=os.environ['USER'], tmpdir=memory_temp_dir))
23+
user = os.environ["USER"]
24+
fd.write(
25+
dedent(
26+
f"""
27+
[mysqld]
28+
user = {user}
29+
tmpdir = {memory_temp_dir}
30+
default-time-zone = SYSTEM
31+
"""
32+
)
33+
)
2934
return defaults_path
35+
return None
3036

3137

3238
@pytest.fixture(scope='session')
3339
def mysql_base_dir():
34-
my_print_defaults = find_executable('my_print_defaults')
40+
my_print_defaults = shutil.which('my_print_defaults')
3541
assert my_print_defaults, 'You have to install my_print_defaults script.'
3642

3743
return os.path.dirname(os.path.dirname(os.path.realpath(my_print_defaults)))
@@ -49,7 +55,7 @@ def mysql_system_database(
4955
):
5056
"""Install database to given path."""
5157
if run_services:
52-
mysqld = find_executable('mysqld')
58+
mysqld = shutil.which('mysqld')
5359
assert mysqld, 'You have to install mysqld script.'
5460

5561
try:

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ deps =
1111
xdist: pytest-xdist
1212
-r{toxinidir}/requirements-testing.txt
1313
extras = memcache
14+
passenv = USER
1415

1516
[pytest]
1617
addopts = -v -ra

0 commit comments

Comments
 (0)