Skip to content

Commit

Permalink
Ignore non-test section names and invalid factor filters (#2748)
Browse files Browse the repository at this point in the history
Resolves #2746
  • Loading branch information
gaborbernat committed Dec 18, 2022
1 parent 50985fe commit 569268a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/2746.bugfix.rst
@@ -0,0 +1,2 @@
Do not include non test environment sections or factor filters in INI configuration to factor discovery - by
:user:`gaborbernat`.
2 changes: 1 addition & 1 deletion src/tox/config/loader/ini/factor.py
Expand Up @@ -73,7 +73,7 @@ def expand_env_with_negation(value: str) -> Iterator[str]:
if key:
group_str = "".join(group).strip()
elements = re.split(r"{([^}]+)}", group_str)
parts = [re.sub(r"\s+", "", elem).split(",") for elem in elements]
parts = [[i.strip() for i in elem.split(",")] for elem in elements]
for variant in product(*parts):
variant_str = "".join(variant)
if not re.fullmatch(r"!?[\w._][\w._-]*", variant_str):
Expand Down
6 changes: 3 additions & 3 deletions src/tox/config/source/ini.py
Expand Up @@ -83,9 +83,9 @@ def register_factors(envs: Iterable[str]) -> None:

# discover all additional defined environments, including generative section headers
for section in self.sections():
register_factors(section.names)
for name in section.names:
if section.is_test_env:
if section.is_test_env:
register_factors(section.names)
for name in section.names:
self._section_mapping[name].append(section.key)
yield name
# add all conditional markers that are not part of the explicitly defined sections
Expand Down
12 changes: 12 additions & 0 deletions tests/config/source/test_source_ini.py
Expand Up @@ -10,3 +10,15 @@ def test_source_ini_with_interpolated(tmp_path: Path) -> None:
loader = IniSource(tmp_path, content="[tox]\na = %(c)s").get_loader(Section(None, "tox"), {})
assert loader is not None
loader.load_raw("a", None, None)


def test_source_ini_ignore_non_testenv_sections(tmp_path: Path) -> None:
loader = IniSource(tmp_path, content="[mypy-rest_framework.compat.*]")
res = list(loader.envs({"env_list": []})) # type: ignore
assert not res


def test_source_ini_ignore_invalid_factor_filters(tmp_path: Path) -> None:
loader = IniSource(tmp_path, content="[a]\nb= if c: d")
res = list(loader.envs({"env_list": []})) # type: ignore
assert not res

0 comments on commit 569268a

Please sign in to comment.