From 267a596a032ba46b21314aff49b3b7d3af37a180 Mon Sep 17 00:00:00 2001 From: Jeff Quast Date: Mon, 23 Mar 2020 04:31:34 -0700 Subject: [PATCH] Fix ValueError: max() arg is an empty sequence on (#1529) * fix ValueError: max() arg is an empty sequence When running `tox -l` with a tox.ini file not containing any default environments, instead of an empty output, an exception is raised: ``` $ tox -l tox -l Traceback (most recent call last): File "/Users/jq/.pyenv/versions/py38/bin/tox", line 8, in sys.exit(cmdline()) File "/Users/jq/.pyenv/versions/3.8.1/envs/py38/lib/python3.8/site-packages/tox/session/__init__.py", line 44, in cmdline main(args) File "/Users/jq/.pyenv/versions/3.8.1/envs/py38/lib/python3.8/site-packages/tox/session/__init__.py", line 68, in main exit_code = session.runcommand() File "/Users/jq/.pyenv/versions/3.8.1/envs/py38/lib/python3.8/site-packages/tox/session/__init__.py", line 189, in runcommand self.showenvs(all_envs=False, description=show_description) File "/Users/jq/.pyenv/versions/3.8.1/envs/py38/lib/python3.8/site-packages/tox/session/__init__.py", line 293, in showenvs show_envs(self.config, all_envs=all_envs, description=description) File "/Users/jq/.pyenv/versions/3.8.1/envs/py38/lib/python3.8/site-packages/tox/session/commands/show_env.py", line 14, in show_envs max_length = max((len(env) for env in (default + extra))) ValueError: max() arg is an empty sequence ``` * trying to follow contributing guidelines * add test, fails without merge, succeeds after Signed-off-by: Bernat Gabor --- docs/changelog/1343.bug.rst | 1 + src/tox/session/commands/show_env.py | 2 +- tests/unit/session/test_list_env.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/1343.bug.rst diff --git a/docs/changelog/1343.bug.rst b/docs/changelog/1343.bug.rst new file mode 100644 index 0000000000..027f875586 --- /dev/null +++ b/docs/changelog/1343.bug.rst @@ -0,0 +1 @@ +Fix ValueError on ``tox -l`` for a ``tox.ini`` file that does not contain an ``envlist`` definition. - by :user:`jquast` diff --git a/src/tox/session/commands/show_env.py b/src/tox/session/commands/show_env.py index ae05c84db6..1ed9ba9371 100644 --- a/src/tox/session/commands/show_env.py +++ b/src/tox/session/commands/show_env.py @@ -11,7 +11,7 @@ def show_envs(config, all_envs=False, description=False): if description and default: report.line("default environments:") - max_length = max(len(env) for env in (default + extra)) + max_length = max(len(env) for env in (default + extra) or [""]) def report_env(e): if description: diff --git a/tests/unit/session/test_list_env.py b/tests/unit/session/test_list_env.py index 8281a8296e..e0217c6d6f 100644 --- a/tests/unit/session/test_list_env.py +++ b/tests/unit/session/test_list_env.py @@ -216,3 +216,13 @@ def test_listenvs_all_extra_definition_order_increasing(cmd, initproj): result = cmd("-a") expected = ["py36", "a", "b"] assert result.outlines == expected + + +def test_listenvs_without_default_envs(cmd, initproj): + """When running tox -l without any default envirinments, nothing happens.""" + initproj( + "logsnada", filedefs={"tox.ini": ""}, + ) + result = cmd("-l") + assert result.ret == 0 + assert result.out == ""