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

Set always PYTHONIOENCODING to utf-8 #2646

Merged
merged 1 commit into from Dec 8, 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/2422.bugfix.rst
@@ -0,0 +1,2 @@
Always set environment variable ``PYTHONIOENCODING`` to ``utf-8`` to ensure tox works under Windows custom encodings
- by :user:`gaborbernat`.
1 change: 1 addition & 0 deletions src/tox/config/sets.py
Expand Up @@ -217,6 +217,7 @@ def __init__(self, conf: Config, section: Section, env_name: str) -> None:
def register_config(self) -> None:
def set_env_post_process(values: SetEnv) -> SetEnv:
values.update(self.default_set_env_loader(), override=False)
values.update({"PYTHONIOENCODING": "utf-8"}, override=True)
return values

def set_env_factory(raw: object) -> SetEnv:
Expand Down
7 changes: 4 additions & 3 deletions tests/config/test_set_env.py
Expand Up @@ -60,9 +60,9 @@ def func(tox_ini: str, extra_files: dict[str, Any] | None = None, from_cwd: Path
def test_set_env_default(eval_set_env: EvalSetEnv) -> None:
set_env = eval_set_env("")
keys = list(set_env)
assert keys == ["PIP_DISABLE_PIP_VERSION_CHECK"]
assert keys == ["PIP_DISABLE_PIP_VERSION_CHECK", "PYTHONIOENCODING"]
values = [set_env.load(k) for k in keys]
assert values == ["1"]
assert values == ["1", "utf-8"]


def test_set_env_self_key(eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch) -> None:
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_set_env_replacer(eval_set_env: EvalSetEnv, monkeypatch: MonkeyPatch) ->
monkeypatch.setenv("MAGIC", "\nb=2\n")
set_env = eval_set_env("[testenv]\npackage=skip\nset_env=a=1\n {env:MAGIC}")
env = {k: set_env.load(k) for k in set_env}
assert env == {"PIP_DISABLE_PIP_VERSION_CHECK": "1", "a": "1", "b": "2"}
assert env == {"PIP_DISABLE_PIP_VERSION_CHECK": "1", "a": "1", "b": "2", "PYTHONIOENCODING": "utf-8"}


def test_set_env_honor_override(eval_set_env: EvalSetEnv) -> None:
Expand Down Expand Up @@ -148,6 +148,7 @@ def test_set_env_environment_file(eval_set_env: EvalSetEnv) -> None:
"C": "1",
"E": '"1"',
"F": "",
"PYTHONIOENCODING": "utf-8",
}


Expand Down
2 changes: 1 addition & 1 deletion tests/session/cmd/test_show_config.py
Expand Up @@ -160,7 +160,7 @@ def test_show_config_select_only(tox_project: ToxProjectCreator) -> None:
def test_show_config_alias(tox_project: ToxProjectCreator) -> None:
outcome = tox_project({"tox.ini": ""}).run("c", "-e", "py", "-k", "setenv")
outcome.assert_success()
assert "set_env = " in outcome.out
assert "set_env =" in outcome.out


def test_show_config_description_normalize(tox_project: ToxProjectCreator) -> None:
Expand Down