Skip to content

Commit 0b5726f

Browse files
hroncokssbarnea
authored andcommitted
Allow to use --devenv without tox config (tox-dev#1644)
Fixes tox-dev#1643
1 parent 5313d65 commit 0b5726f

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

docs/changelog/1643.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't require a tox config file for ``tox --devenv`` - by :user:`hroncok`

docs/example/devenv.rst

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ If you don't specify an environment with ``-e``, the devenv feature will
3535
default to ``-e py`` -- usually taking the interpreter you're running ``tox``
3636
with and the default ``[testenv]`` configuration.
3737

38+
It is possible to use the ``--devenv`` option without a tox configuration file,
39+
however the configuration file is respected if present.
40+
3841
Creating development environments using configuration
3942
=====================================================
4043

src/tox/config/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ def parseconfig(args, plugins=()):
285285
parser.parse_cli(args, strict=True)
286286
if option.help or option.helpini:
287287
return config
288+
if option.devenv:
289+
# To load defaults, we parse an empty config
290+
ParseIni(config, py.path.local(), "")
291+
pm.hook.tox_configure(config=config)
292+
return config
288293
msg = "tox config file (either {}) not found"
289294
candidates = ", ".join(INFO.CONFIG_CANDIDATES)
290295
feedback(msg.format(candidates), sysexit=not (option.help or option.helpini))
@@ -1056,7 +1061,7 @@ class ParseIni(object):
10561061
def __init__(self, config, ini_path, ini_data): # noqa
10571062
config.toxinipath = ini_path
10581063
using("tox.ini: {} (pid {})".format(config.toxinipath, os.getpid()))
1059-
config.toxinidir = config.toxinipath.dirpath()
1064+
config.toxinidir = config.toxinipath.dirpath() if ini_path.check(file=True) else ini_path
10601065

10611066
self._cfg = py.iniconfig.IniConfig(config.toxinipath, ini_data)
10621067

tests/unit/config/test_config.py

+11
Original file line numberDiff line numberDiff line change
@@ -3038,6 +3038,17 @@ def test_config_setup_cfg_no_tox_section(initproj, capsys):
30383038
assert "ERROR:" not in out
30393039

30403040

3041+
def test_config_file_not_required_with_devenv(initproj, capsys):
3042+
initproj("no_tox_config-0.7")
3043+
config = parseconfig(["--devenv", "myenv"])
3044+
3045+
out, err = capsys.readouterr()
3046+
assert "ERROR:" not in err
3047+
assert "ERROR:" not in out
3048+
assert config.option.devenv == "myenv"
3049+
assert config.option.notest is True
3050+
3051+
30413052
@pytest.mark.skipif(sys.platform == "win32", reason="no named pipes on Windows")
30423053
def test_config_bad_config_type_specified(monkeypatch, tmpdir, capsys):
30433054
monkeypatch.chdir(tmpdir)

tests/unit/test_z_cmdline.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -882,24 +882,28 @@ def test_notest_setup_py_error(initproj, cmd):
882882
assert re.search("ERROR:.*InvocationError", result.out)
883883

884884

885-
def test_devenv(initproj, cmd):
886-
initproj(
887-
"example123",
888-
filedefs={
889-
"setup.py": """\
890-
from setuptools import setup
891-
setup(name='x')
892-
""",
893-
"tox.ini": """\
885+
@pytest.mark.parametrize("has_config", [True, False])
886+
def test_devenv(initproj, cmd, has_config):
887+
filedefs = {
888+
"setup.py": """\
889+
from setuptools import setup
890+
setup(name='x')
891+
""",
892+
}
893+
if has_config:
894+
filedefs[
895+
"tox.ini"
896+
] = """\
894897
[tox]
895898
# envlist is ignored for --devenv
896899
envlist = foo,bar,baz
897900
898901
[testenv]
899902
# --devenv implies --notest
900903
commands = python -c "exit(1)"
901-
""",
902-
},
904+
"""
905+
initproj(
906+
"example123", filedefs=filedefs,
903907
)
904908
result = cmd("--devenv", "venv")
905909
result.assert_success()

0 commit comments

Comments
 (0)