Skip to content

Commit 569268a

Browse files
authored
Ignore non-test section names and invalid factor filters (#2748)
Resolves #2746
1 parent 50985fe commit 569268a

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

docs/changelog/2746.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Do not include non test environment sections or factor filters in INI configuration to factor discovery - by
2+
:user:`gaborbernat`.

src/tox/config/loader/ini/factor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def expand_env_with_negation(value: str) -> Iterator[str]:
7373
if key:
7474
group_str = "".join(group).strip()
7575
elements = re.split(r"{([^}]+)}", group_str)
76-
parts = [re.sub(r"\s+", "", elem).split(",") for elem in elements]
76+
parts = [[i.strip() for i in elem.split(",")] for elem in elements]
7777
for variant in product(*parts):
7878
variant_str = "".join(variant)
7979
if not re.fullmatch(r"!?[\w._][\w._-]*", variant_str):

src/tox/config/source/ini.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ def register_factors(envs: Iterable[str]) -> None:
8383

8484
# discover all additional defined environments, including generative section headers
8585
for section in self.sections():
86-
register_factors(section.names)
87-
for name in section.names:
88-
if section.is_test_env:
86+
if section.is_test_env:
87+
register_factors(section.names)
88+
for name in section.names:
8989
self._section_mapping[name].append(section.key)
9090
yield name
9191
# add all conditional markers that are not part of the explicitly defined sections

tests/config/source/test_source_ini.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ def test_source_ini_with_interpolated(tmp_path: Path) -> None:
1010
loader = IniSource(tmp_path, content="[tox]\na = %(c)s").get_loader(Section(None, "tox"), {})
1111
assert loader is not None
1212
loader.load_raw("a", None, None)
13+
14+
15+
def test_source_ini_ignore_non_testenv_sections(tmp_path: Path) -> None:
16+
loader = IniSource(tmp_path, content="[mypy-rest_framework.compat.*]")
17+
res = list(loader.envs({"env_list": []})) # type: ignore
18+
assert not res
19+
20+
21+
def test_source_ini_ignore_invalid_factor_filters(tmp_path: Path) -> None:
22+
loader = IniSource(tmp_path, content="[a]\nb= if c: d")
23+
res = list(loader.envs({"env_list": []})) # type: ignore
24+
assert not res

0 commit comments

Comments
 (0)