1
0
mirror of https://github.com/fedora-python/tox-current-env.git synced 2025-07-02 23:53:04 +02:00

Only use tox_cleanup hook when it is possible

This commit is contained in:
Miro Hrončok 2019-08-01 14:46:01 +02:00
parent a645fe2175
commit cf04976cea
3 changed files with 30 additions and 12 deletions

View File

@ -85,10 +85,15 @@ def unsupported_raise(config, venv):
return
regular = not (config.option.current_env or config.option.print_deps_only)
if regular and is_current_env_link(venv):
if hasattr(tox.hookspecs, "tox_cleanup"):
raise tox.exception.ConfigError(
"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):
raise tox.exception.ConfigError(
"--current-env after regular tox run is not supported without --recreate (-r)."
@ -166,6 +171,8 @@ def tox_runtest(venv, redirect):
return True
if hasattr(tox.hookspecs, "tox_cleanup"):
@tox.hookimpl
def tox_cleanup(session):
"""Remove the fake virtualenv not to collide with regular tox

View File

@ -6,6 +6,8 @@ import subprocess
import sys
import textwrap
from packaging import version
import pytest
@ -37,6 +39,8 @@ def is_available(python):
return True
TOX_VERSION = version.parse(tox("--version").stdout.split(" ")[0])
needs_py3678 = pytest.mark.skipif(
not is_available("python3.6")
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",
)
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():
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
@needs_tox38
def test_regular_after_current_is_supported():
result = tox("-e", NATIVE_TOXENV, "--current-env")
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
@needs_tox38
def test_regular_after_first_deps_only_is_supported():
result = tox("-e", NATIVE_TOXENV, "--print-deps-only")
assert result.stdout.splitlines()[0] == "six"

View File

@ -4,6 +4,7 @@ envlist = {py36,py37,py38}-tox{35,release,master}
[testenv]
deps=
pytest
packaging
tox35: tox >=3.5,<3.6
toxrelease: tox
toxmaster: git+https://github.com/tox-dev/tox.git@master