Skip to content

Commit

Permalink
Remove incorrect user of TOX_WORK_DIR global
Browse files Browse the repository at this point in the history
# Conflicts:
#	.config/constraints.txt
#	.pre-commit-config.yaml
  • Loading branch information
ssbarnea committed Feb 1, 2025
1 parent 6b51c44 commit 1cf791f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
17 changes: 8 additions & 9 deletions src/tox_ansible/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
{integration, sanity, unit}-py3.12-{2.16, 2.17, 2.18, milestone, devel}
{integration, sanity, unit}-py3.13-{2.18, milestone, devel}
"""
TOX_WORK_DIR = Path()
# Without the minimal pytest-ansible condition, installation may fail in some
# cases (pip, uv).
OUR_DEPS = [
Expand Down Expand Up @@ -178,8 +177,6 @@ def tox_add_core_config(
)
logging.warning(msg)

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

if not state.conf.options.gh_matrix:
Expand Down Expand Up @@ -209,7 +206,7 @@ def tox_add_env_config(env_conf: EnvConfigSet, state: State) -> None:
]:
return

galaxy_path = TOX_WORK_DIR / "galaxy.yml"
galaxy_path = env_conf._conf._root / "galaxy.yml" # noqa: SLF001
c_name, c_namespace = get_collection_name(galaxy_path=galaxy_path)
pos_args = state.conf.pos_args(to_path=None)

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

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


Expand Down Expand Up @@ -521,7 +519,7 @@ def conf_commands_pre(
if in_action():
group = "echo ::group::Copy the collection to the galaxy build dir"
commands.append(group)
cd_tox_dir = f"cd {TOX_WORK_DIR}"
cd_tox_dir = f"cd {env_conf._conf._root.as_posix()}" # noqa: SLF001
copy_script = (
f"for file in $(git ls-files 2> /dev/null || ls); do\n\t"
f"mkdir -p {galaxy_build_dir}/$(dirname $file);\n\t"
Expand Down Expand Up @@ -570,20 +568,21 @@ def conf_deps(env_conf: EnvConfigSet, test_type: str) -> str:
The dependencies.
"""
deps = []
root = env_conf._conf._root # noqa: SLF001
if test_type in ["integration", "unit"]:
deps.extend(OUR_DEPS)
try:
with (TOX_WORK_DIR / "test-requirements.txt").open() as fileh:
with (root / "test-requirements.txt").open() as fileh:
deps.extend(fileh.read().splitlines())
except FileNotFoundError:
pass
try:
with (TOX_WORK_DIR / "requirements-test.txt").open() as fileh:
with (root / "requirements-test.txt").open() as fileh:
deps.extend(fileh.read().splitlines())
except FileNotFoundError:
pass
try:
with (TOX_WORK_DIR / "requirements.txt").open() as fileh:
with (root / "requirements.txt").open() as fileh:
deps.extend(fileh.read().splitlines())
except FileNotFoundError:
pass
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ def test_conf_commands_unit(tmp_path: Path) -> None:
pos_args=None,
)
assert len(result) == 1
assert result[0] == "python3 -m pytest --ansible-unit-inject-only ./tests/unit"
path = Path("./tests/unit").resolve().as_posix()
assert result[0] == f"python3 -m pytest --ansible-unit-inject-only {path}"


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


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


def test_conf_deps(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
def test_conf_deps(tmp_path: Path) -> None:
"""Test the conf_commands function.
Args:
Expand All @@ -329,7 +331,6 @@ def test_conf_deps(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
(tmp_path / "test-requirements.txt").write_text("test-requirement")
(tmp_path / "requirements.txt").write_text("requirement")
(tmp_path / "requirements-test.txt").write_text("requirement-test")
monkeypatch.setattr("tox_ansible.plugin.TOX_WORK_DIR", tmp_path)

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

0 comments on commit 1cf791f

Please sign in to comment.