From 1cf791f2afb3464854553f2d6e9770108307bb83 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 30 Jan 2025 13:16:19 +0000 Subject: [PATCH] Remove incorrect user of TOX_WORK_DIR global # Conflicts: # .config/constraints.txt # .pre-commit-config.yaml --- src/tox_ansible/plugin.py | 17 ++++++++--------- tests/unit/test_plugin.py | 9 +++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/tox_ansible/plugin.py b/src/tox_ansible/plugin.py index 5bbb168..6e42004 100644 --- a/src/tox_ansible/plugin.py +++ b/src/tox_ansible/plugin.py @@ -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 = [ @@ -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: @@ -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) @@ -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] @@ -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" @@ -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 diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py index 39fc5ca..96643be 100644 --- a/tests/unit/test_plugin.py +++ b/tests/unit/test_plugin.py @@ -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: @@ -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: @@ -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: @@ -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),