Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non-test section names and invalid factor filters #2748

Merged
merged 1 commit into from Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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