Skip to content

Commit

Permalink
Fix ValueError: max() arg is an empty sequence on (tox-dev#1529)
Browse files Browse the repository at this point in the history
* 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 <module>
    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 <[email protected]>
  • Loading branch information
jquast authored and ssbarnea committed Apr 19, 2021
1 parent c06571c commit 267a596
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/1343.bug.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ValueError on ``tox -l`` for a ``tox.ini`` file that does not contain an ``envlist`` definition. - by :user:`jquast`
2 changes: 1 addition & 1 deletion src/tox/session/commands/show_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/session/test_list_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""

0 comments on commit 267a596

Please sign in to comment.