Skip to content

Commit 1b5b187

Browse files
authored
Document how CliEnv works (#3206)
1 parent b3eb86a commit 1b5b187

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/tox/session/env_select.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,22 @@
2727

2828

2929
class CliEnv: # noqa: PLW1641
30-
"""CLI tox env selection."""
30+
"""A `CliEnv` is the user's selection of tox test environments, usually supplied via the ``-e`` command-line
31+
option. It may be treated as a sequence if it's not a "default" or "all" selection.
32+
33+
It is in one of three forms:
34+
35+
- A list of specific environments, instantiated with a string that is a comma-separated list of the environment
36+
names. As a sequence this will be a sequence of those names.
37+
38+
- "ALL" which is all environments defined by the tox configuration. This is instantiated with ``ALL`` either
39+
alone or as any element of a comma-separated list; any other environment names are ignored. `is_all()` will be
40+
true and as a sequence it will be empty. This prints in string representation as ``ALL``.
41+
42+
- The default environments as chosen by tox configuration. This is instantiated with `None` as the parameter,
43+
`is_default_list()` will be true, and as a sequence this will be empty. This prints in string representation
44+
as ``<env_list>``.
45+
"""
3146

3247
def __init__(self, value: None | list[str] | str = None) -> None:
3348
if isinstance(value, str):
@@ -39,6 +54,7 @@ def __iter__(self) -> Iterator[str]:
3954
yield from self._names
4055

4156
def __bool__(self) -> bool:
57+
"""A `CliEnv` is `True` if it's not the default set of environments."""
4258
return bool(self._names)
4359

4460
def __str__(self) -> str:

tests/session/test_env_select.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
def test_clienv(user_input: str, env_names: tuple[str], is_all: bool, is_default: bool) -> None:
3737
ce = CliEnv(user_input)
3838
assert (ce.is_all, ce.is_default_list, tuple(ce)) == (is_all, is_default, tuple(env_names))
39+
assert ce is not ce.is_default_list
40+
assert CliEnv(user_input) == ce
3941

4042

4143
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)