From c9fe58c8ebfa888cdb6e1318143d99a2f92c703d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 17 Jul 2019 18:54:39 +0200 Subject: [PATCH] Handle tox -r after --current-env --- src/tox_current_env/hooks.py | 6 +++++- tests/test_integration.py | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index c9854b7..08ef9c9 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -56,10 +56,14 @@ def tox_testenv_create(venv, action): # Remove the rest of the virtualenv. link = venv.envconfig.get_envpython() target = sys.executable - shutil.rmtree(os.path.dirname(link), ignore_errors=True) + shutil.rmtree(os.path.dirname(os.path.dirname(link)), ignore_errors=True) os.makedirs(os.path.dirname(link)) os.symlink(target, link) return True + else: + link = venv.envconfig.get_envpython() + shutil.rmtree(os.path.dirname(os.path.dirname(link)), ignore_errors=True) + return None # let tox handle the rest @tox.hookimpl diff --git a/tests/test_integration.py b/tests/test_integration.py index 2d7fdfd..2dcda1a 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -66,7 +66,6 @@ def test_regular_after_current(): assert f"/.tox/{NATIVE_TOXENV}/bin/python" in result.stdout.splitlines()[0] -@pytest.mark.xfail(reason="Regular tox refuses to remove our fake virtualenv") def test_regular_recreate_after_current(): tox("-e", NATIVE_TOXENV, "--current-env") tox("-re", NATIVE_TOXENV, prune=False)