Skip to content

Commit

Permalink
Merge pull request #366 from tox-dev/fix-352
Browse files Browse the repository at this point in the history
catch project deletion if envdir==toxinidir
  • Loading branch information
hpk42 authored Oct 11, 2016
2 parents c3e383c + 55af862 commit 3e66f01
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
2.4.0
-----

- fix issue352: prevent a configuration where envdir==toxinidir and
refine docs to warn people about changing "envdir". Thanks Oliver Bestwalter and holger krekel.

- fix issue375, fix issue330: warn against tox-setup.py integration as
"setup.py test" should really just test with the current interpreter. Thanks Ronny Pfannschmidt.

Expand Down
14 changes: 14 additions & 0 deletions tests/test_z_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ def test_minversion(cmd, initproj):
])
assert result.ret

def test_envdir_equals_toxini_errors_out(cmd, initproj):
initproj("interp123-0.7", filedefs={
'tox.ini': '''
[testenv]
envdir={toxinidir}
'''
})
result = cmd.run("tox")
result.stdout.fnmatch_lines([
"ERROR*venv*delete*",
"*ConfigError*envdir must not equal toxinidir*",
])
assert result.ret


def test_run_custom_install_command_error(cmd, initproj):
initproj("interp123-0.5", filedefs={
Expand Down
3 changes: 2 additions & 1 deletion tox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ def tox_addoption(parser):

parser.add_testenv_attribute(
name="envdir", type="path", default="{toxworkdir}/{envname}",
help="venv directory")
help="set venv directory -- be very careful when changing this as tox "
"will remove this directory when recreating an environment")

# add various core venv interpreter attributes
def setenv(testenv_config, value):
Expand Down
7 changes: 7 additions & 0 deletions tox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ def __init__(self, config, popen=subprocess.Popen, Report=Reporter):
]
except LookupError:
raise SystemExit(1)
except tox.exception.ConfigError as e:
self.report.error(str(e))
raise SystemExit(1)
self._actions = []

@property
Expand All @@ -356,6 +359,10 @@ def _makevenv(self, name):
if envconfig is None:
self.report.error("unknown environment %r" % name)
raise LookupError(name)
elif envconfig.envdir == self.config.toxinidir:
self.report.error(
"venv %r in %s would delete project" % (name, envconfig.envdir))
raise tox.exception.ConfigError('envdir must not equal toxinidir')
venv = VirtualEnv(envconfig=envconfig, session=self)
self._name2venv[name] = venv
return venv
Expand Down

0 comments on commit 3e66f01

Please sign in to comment.