Skip to content

Commit d832f39

Browse files
committed
Ensure automatically provisioned environment is torn down.
1 parent b33a43c commit d832f39

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/tox/provision.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ def run_provision(name: str, state: State) -> int:
146146
logging.info("will run in a automatically provisioned python environment under %s", env_python)
147147
try:
148148
tox_env.setup()
149+
args: list[str] = [str(env_python), "-m", "tox"]
150+
args.extend(state.args)
151+
outcome = tox_env.execute(cmd=args, stdin=StdinSource.user_only(), show=True, run_id="provision", cwd=Path.cwd())
152+
return cast("int", outcome.exit_code)
149153
except Skip as exception:
150154
msg = f"cannot provision tox environment {tox_env.conf['env_name']} because {exception}"
151155
raise HandledError(msg) from exception
152-
args: list[str] = [str(env_python), "-m", "tox"]
153-
args.extend(state.args)
154-
outcome = tox_env.execute(cmd=args, stdin=StdinSource.user_only(), show=True, run_id="provision", cwd=Path.cwd())
155-
return cast("int", outcome.exit_code)
156+
finally:
157+
tox_env.teardown()

src/tox/tox_env/package.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def mark_active_run_env(self, run_env: RunToxEnv) -> None:
9797
self._envs.add(run_env.conf.name)
9898

9999
def teardown_env(self, conf: EnvConfigSet) -> None:
100-
self._envs.remove(conf.name)
100+
if conf.name in self._envs:
101+
self._envs.remove(conf.name)
101102
if len(self._envs) == 0:
102103
self._teardown()
103104

0 commit comments

Comments
 (0)