Skip to content

Commit 1cf791f

Browse files
committed
Remove incorrect user of TOX_WORK_DIR global
# Conflicts: # .config/constraints.txt # .pre-commit-config.yaml
1 parent 6b51c44 commit 1cf791f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/tox_ansible/plugin.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
{integration, sanity, unit}-py3.12-{2.16, 2.17, 2.18, milestone, devel}
4848
{integration, sanity, unit}-py3.13-{2.18, milestone, devel}
4949
"""
50-
TOX_WORK_DIR = Path()
5150
# Without the minimal pytest-ansible condition, installation may fail in some
5251
# cases (pip, uv).
5352
OUR_DEPS = [
@@ -178,8 +177,6 @@ def tox_add_core_config(
178177
)
179178
logging.warning(msg)
180179

181-
global TOX_WORK_DIR # pylint: disable=global-statement # noqa: PLW0603
182-
TOX_WORK_DIR = state.conf.work_dir
183180
env_list = add_ansible_matrix(state)
184181

185182
if not state.conf.options.gh_matrix:
@@ -209,7 +206,7 @@ def tox_add_env_config(env_conf: EnvConfigSet, state: State) -> None:
209206
]:
210207
return
211208

212-
galaxy_path = TOX_WORK_DIR / "galaxy.yml"
209+
galaxy_path = env_conf._conf._root / "galaxy.yml" # noqa: SLF001
213210
c_name, c_namespace = get_collection_name(galaxy_path=galaxy_path)
214211
pos_args = state.conf.pos_args(to_path=None)
215212

@@ -449,10 +446,11 @@ def conf_commands_for_integration_unit(
449446
The commands to run.
450447
"""
451448
args = f" {' '.join(pos_args)} " if pos_args else " "
449+
root = Path(__file__).parents[2].resolve()
452450

453451
# Use pytest ansible unit inject only to inject the collection path
454452
# into the collection finder
455-
command = f"python3 -m pytest --ansible-unit-inject-only{args}{TOX_WORK_DIR}/tests/{test_type}"
453+
command = f"python3 -m pytest --ansible-unit-inject-only{args}{root}/tests/{test_type}"
456454
return [command]
457455

458456

@@ -521,7 +519,7 @@ def conf_commands_pre(
521519
if in_action():
522520
group = "echo ::group::Copy the collection to the galaxy build dir"
523521
commands.append(group)
524-
cd_tox_dir = f"cd {TOX_WORK_DIR}"
522+
cd_tox_dir = f"cd {env_conf._conf._root.as_posix()}" # noqa: SLF001
525523
copy_script = (
526524
f"for file in $(git ls-files 2> /dev/null || ls); do\n\t"
527525
f"mkdir -p {galaxy_build_dir}/$(dirname $file);\n\t"
@@ -570,20 +568,21 @@ def conf_deps(env_conf: EnvConfigSet, test_type: str) -> str:
570568
The dependencies.
571569
"""
572570
deps = []
571+
root = env_conf._conf._root # noqa: SLF001
573572
if test_type in ["integration", "unit"]:
574573
deps.extend(OUR_DEPS)
575574
try:
576-
with (TOX_WORK_DIR / "test-requirements.txt").open() as fileh:
575+
with (root / "test-requirements.txt").open() as fileh:
577576
deps.extend(fileh.read().splitlines())
578577
except FileNotFoundError:
579578
pass
580579
try:
581-
with (TOX_WORK_DIR / "requirements-test.txt").open() as fileh:
580+
with (root / "requirements-test.txt").open() as fileh:
582581
deps.extend(fileh.read().splitlines())
583582
except FileNotFoundError:
584583
pass
585584
try:
586-
with (TOX_WORK_DIR / "requirements.txt").open() as fileh:
585+
with (root / "requirements.txt").open() as fileh:
587586
deps.extend(fileh.read().splitlines())
588587
except FileNotFoundError:
589588
pass

tests/unit/test_plugin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ def test_conf_commands_unit(tmp_path: Path) -> None:
221221
pos_args=None,
222222
)
223223
assert len(result) == 1
224-
assert result[0] == "python3 -m pytest --ansible-unit-inject-only ./tests/unit"
224+
path = Path("./tests/unit").resolve().as_posix()
225+
assert result[0] == f"python3 -m pytest --ansible-unit-inject-only {path}"
225226

226227

227228
def test_conf_commands_sanity(tmp_path: Path) -> None:
@@ -282,7 +283,8 @@ def test_conf_commands_integration(tmp_path: Path) -> None:
282283
pos_args=None,
283284
)
284285
assert len(result) == 1
285-
assert result[0] == "python3 -m pytest --ansible-unit-inject-only ./tests/integration"
286+
path = Path("./tests/integration").resolve().as_posix()
287+
assert result[0] == f"python3 -m pytest --ansible-unit-inject-only {path}"
286288

287289

288290
def test_conf_commands_invalid(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
@@ -315,7 +317,7 @@ def test_conf_commands_invalid(tmp_path: Path, caplog: pytest.LogCaptureFixture)
315317
assert "Unknown test type" in logs
316318

317319

318-
def test_conf_deps(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
320+
def test_conf_deps(tmp_path: Path) -> None:
319321
"""Test the conf_commands function.
320322
321323
Args:
@@ -329,7 +331,6 @@ def test_conf_deps(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
329331
(tmp_path / "test-requirements.txt").write_text("test-requirement")
330332
(tmp_path / "requirements.txt").write_text("requirement")
331333
(tmp_path / "requirements-test.txt").write_text("requirement-test")
332-
monkeypatch.setattr("tox_ansible.plugin.TOX_WORK_DIR", tmp_path)
333334

334335
conf = Config.make(
335336
Parsed(work_dir=tmp_path, override=[], config_file=ini_file, root_dir=tmp_path),

0 commit comments

Comments
 (0)