mirror of
https://github.com/fedora-python/tox-current-env.git
synced 2025-05-06 21:06:56 +02:00
Only use tox_cleanup hook when it is possible
This commit is contained in:
parent
a645fe2175
commit
cf04976cea
@ -85,10 +85,15 @@ def unsupported_raise(config, venv):
|
|||||||
return
|
return
|
||||||
regular = not (config.option.current_env or config.option.print_deps_only)
|
regular = not (config.option.current_env or config.option.print_deps_only)
|
||||||
if regular and is_current_env_link(venv):
|
if regular and is_current_env_link(venv):
|
||||||
raise tox.exception.ConfigError(
|
if hasattr(tox.hookspecs, "tox_cleanup"):
|
||||||
"Looks like previous --current-env or --print-deps-only tox run didn't finish the cleanup. "
|
raise tox.exception.ConfigError(
|
||||||
"Run tox run with --recreate (-r) or manually remove the environment in .tox."
|
"Looks like previous --current-env or --print-deps-only tox run didn't finish the cleanup. "
|
||||||
)
|
"Run tox run with --recreate (-r) or manually remove the environment in .tox."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise tox.exception.ConfigError(
|
||||||
|
"Regular tox run after --current-env or --print-deps-only tox run is not supported without --recreate (-r)."
|
||||||
|
)
|
||||||
elif config.option.current_env and is_proper_venv(venv):
|
elif config.option.current_env and is_proper_venv(venv):
|
||||||
raise tox.exception.ConfigError(
|
raise tox.exception.ConfigError(
|
||||||
"--current-env after regular tox run is not supported without --recreate (-r)."
|
"--current-env after regular tox run is not supported without --recreate (-r)."
|
||||||
@ -166,11 +171,13 @@ def tox_runtest(venv, redirect):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@tox.hookimpl
|
if hasattr(tox.hookspecs, "tox_cleanup"):
|
||||||
def tox_cleanup(session):
|
|
||||||
"""Remove the fake virtualenv not to collide with regular tox
|
@tox.hookimpl
|
||||||
Collisions can happen anyway (when tox is killed forcefully before this happens)
|
def tox_cleanup(session):
|
||||||
Note that we don't remove real venvs, as recreating them is expensive"""
|
"""Remove the fake virtualenv not to collide with regular tox
|
||||||
for venv in session.venv_dict.values():
|
Collisions can happen anyway (when tox is killed forcefully before this happens)
|
||||||
if is_current_env_link(venv):
|
Note that we don't remove real venvs, as recreating them is expensive"""
|
||||||
rm_venv(venv)
|
for venv in session.venv_dict.values():
|
||||||
|
if is_current_env_link(venv):
|
||||||
|
rm_venv(venv)
|
||||||
|
@ -6,6 +6,8 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
from packaging import version
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@ -37,6 +39,8 @@ def is_available(python):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
TOX_VERSION = version.parse(tox("--version").stdout.split(" ")[0])
|
||||||
|
|
||||||
needs_py3678 = pytest.mark.skipif(
|
needs_py3678 = pytest.mark.skipif(
|
||||||
not is_available("python3.6")
|
not is_available("python3.6")
|
||||||
or not is_available("python3.7")
|
or not is_available("python3.7")
|
||||||
@ -44,6 +48,10 @@ needs_py3678 = pytest.mark.skipif(
|
|||||||
reason="This test needs all of python3.6, python3.7 and python3.8 to be available in $PATH",
|
reason="This test needs all of python3.6, python3.7 and python3.8 to be available in $PATH",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
needs_tox38 = pytest.mark.skipif(
|
||||||
|
TOX_VERSION < version.parse("3.8"), reason="This test needs at least tox 3.8"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_native_toxenv_current_env():
|
def test_native_toxenv_current_env():
|
||||||
result = tox("-e", NATIVE_TOXENV, "--current-env")
|
result = tox("-e", NATIVE_TOXENV, "--current-env")
|
||||||
@ -195,6 +203,7 @@ def test_regular_run_native_toxenv():
|
|||||||
assert len(list(sitelib.glob(f"{pkg}-*.dist-info"))) == 1
|
assert len(list(sitelib.glob(f"{pkg}-*.dist-info"))) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@needs_tox38
|
||||||
def test_regular_after_current_is_supported():
|
def test_regular_after_current_is_supported():
|
||||||
result = tox("-e", NATIVE_TOXENV, "--current-env")
|
result = tox("-e", NATIVE_TOXENV, "--current-env")
|
||||||
assert result.stdout.splitlines()[0] == NATIVE_EXECUTABLE
|
assert result.stdout.splitlines()[0] == NATIVE_EXECUTABLE
|
||||||
@ -214,6 +223,7 @@ def test_regular_after_killed_current_is_not_supported():
|
|||||||
assert "--recreate" in result.stderr
|
assert "--recreate" in result.stderr
|
||||||
|
|
||||||
|
|
||||||
|
@needs_tox38
|
||||||
def test_regular_after_first_deps_only_is_supported():
|
def test_regular_after_first_deps_only_is_supported():
|
||||||
result = tox("-e", NATIVE_TOXENV, "--print-deps-only")
|
result = tox("-e", NATIVE_TOXENV, "--print-deps-only")
|
||||||
assert result.stdout.splitlines()[0] == "six"
|
assert result.stdout.splitlines()[0] == "six"
|
||||||
|
1
tox.ini
1
tox.ini
@ -4,6 +4,7 @@ envlist = {py36,py37,py38}-tox{35,release,master}
|
|||||||
[testenv]
|
[testenv]
|
||||||
deps=
|
deps=
|
||||||
pytest
|
pytest
|
||||||
|
packaging
|
||||||
tox35: tox >=3.5,<3.6
|
tox35: tox >=3.5,<3.6
|
||||||
toxrelease: tox
|
toxrelease: tox
|
||||||
toxmaster: git+https://github.com/tox-dev/tox.git@master
|
toxmaster: git+https://github.com/tox-dev/tox.git@master
|
||||||
|
Loading…
x
Reference in New Issue
Block a user