diff --git a/src/tox_current_env/hooks4.py b/src/tox_current_env/hooks4.py index 3dec54c..972cf03 100644 --- a/src/tox_current_env/hooks4.py +++ b/src/tox_current_env/hooks4.py @@ -96,7 +96,7 @@ def tox_add_env_config(env_conf, state): # For print-deps-to and print-extras-to, use empty # list of commands so the tox does nothing. if opt.print_deps_to or opt.print_extras_to: - empty_commands = MemoryLoader(commands=[]) + empty_commands = MemoryLoader(commands=[], commands_pre=[], commands_post=[]) env_conf.loaders.insert(0, empty_commands) diff --git a/tests/test_integration_tox4.py b/tests/test_integration_tox4.py index 93594ad..90ca700 100644 --- a/tests/test_integration_tox4.py +++ b/tests/test_integration_tox4.py @@ -40,6 +40,30 @@ def test_print_deps(toxenv, print_deps_stdout_arg): assert prep_tox_output(result.stdout) == expected +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +@pytest.mark.parametrize("pre_post", ["pre", "post", "both"]) +def test_print_deps_with_commands_pre_post(projdir, toxenv, pre_post, print_deps_stdout_arg): + with modify_config(projdir / 'tox.ini') as config: + if pre_post == "both": + config["testenv"]["commands_pre"] = "echo unexpected" + config["testenv"]["commands_post"] = "echo unexpected" + else: + config["testenv"][f"commands_{pre_post}"] = "echo unexpected" + result = tox("-e", toxenv, print_deps_stdout_arg) + expected = textwrap.dedent( + f""" + tox>={TOX_MIN_VERSION} + six + py + {tox_footer(toxenv)} + """ + ).lstrip() + assert sorted(prep_tox_output(result.stdout).splitlines()) == sorted( + expected.splitlines() + ) + assert result.stderr == "" + + @pytest.mark.parametrize("toxenv", envs_from_tox_ini()) def test_print_deps_with_tox_minversion(projdir, toxenv, print_deps_stdout_arg): with modify_config(projdir / "tox.ini") as config: @@ -110,6 +134,29 @@ def test_print_extras(toxenv, print_extras_stdout_arg): ) +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +@pytest.mark.parametrize("pre_post", ["pre", "post", "both"]) +def test_print_extras_with_commands_pre_post(projdir, toxenv, pre_post, print_extras_stdout_arg): + with modify_config(projdir / 'tox.ini') as config: + if pre_post == "both": + config["testenv"]["commands_pre"] = "echo unexpected" + config["testenv"]["commands_post"] = "echo unexpected" + else: + config["testenv"][f"commands_{pre_post}"] = "echo unexpected" + result = tox("-e", toxenv, print_extras_stdout_arg) + expected = textwrap.dedent( + f""" + dev + full + {tox_footer(toxenv)} + """ + ).lstrip() + assert sorted(prep_tox_output(result.stdout).splitlines()) == sorted( + expected.splitlines() + ) + assert result.stderr == "" + + def test_allenvs_print_deps(print_deps_stdout_arg): result = tox(print_deps_stdout_arg) expected = []