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

Fail on blanks in passed env vars #2671

Merged
merged 2 commits into from Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions docs/changelog/2658.feature.rst
@@ -0,0 +1 @@
Fail on ''pass_env/passenv'' entries containing blanks, detecting missing commas
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion src/tox/tox_env/api.py
Expand Up @@ -21,7 +21,7 @@
from tox.execute.request import ExecuteRequest
from tox.journal import EnvJournal
from tox.report import OutErr, ToxHandler
from tox.tox_env.errors import Recreate, Skip
from tox.tox_env.errors import Fail, Recreate, Skip
from tox.tox_env.info import Info
from tox.tox_env.installer import Installer
from tox.util.path import ensure_empty_dir
Expand Down Expand Up @@ -131,6 +131,12 @@ def register_config(self) -> None:
)

def pass_env_post_process(values: list[str]) -> list[str]:
blank_values = [v for v in values if " " in v or "\t" in v]
if blank_values:
raise Fail(
f"pass_env/passenv variable can't have values containing "
f"blanks like {blank_values}; a comma is possibly missing",
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
)
values.extend(self._default_pass_env())
return sorted({k: None for k in values}.keys())

Expand Down
20 changes: 20 additions & 0 deletions tests/tox_env/test_tox_env_api.py
Expand Up @@ -80,6 +80,26 @@ def test_tox_env_pass_env_literal_miss() -> None:
assert not env


def test_tox_env_pass_env_fail(tox_project: ToxProjectCreator) -> None:
prj = tox_project(
{
"tox.ini": """[testenv]
passenv = MYENV YOURENV, THEIRENV
commands=python -c 'import os; print("MYENV", os.getenv("MYENV"))'""",
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
},
)

result = prj.run("r")

result.assert_failed(1)
out = (
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
r"py: failed with pass_env/passenv variable can't have values "
r"containing blanks like \['MYENV YOURENV'\]; "
r"a comma is possibly missing.*"
)
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
result.assert_out_err(out=out, err="", regex=True)


@pytest.mark.parametrize("glob", ["*", "?"])
@pytest.mark.parametrize("char", ["a", "A"])
def test_tox_env_pass_env_match_ignore_case(char: str, glob: str) -> None:
Expand Down