-
-
Notifications
You must be signed in to change notification settings - Fork 451
fix: add encoding arguments #1967
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
Conversation
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
d096fe4
to
2bfdb5f
Compare
Thanks for starting this. It's turning out to be a real puzzle how to silence them all... I'm trying to tweak this to get it right. |
I can try to follow up, but traveling for PyCon is getting in the way. :) I think we just have to fix 3.9 and 3.10. |
This gets us closer: diff --git a/tests/helpers.py b/tests/helpers.py
index b53ee53a..27d757da 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -43,12 +43,14 @@ def run_command(cmd: str) -> tuple[int, str]:
# Subprocesses are expensive, but convenient, and so may be over-used in
# the test suite. Use these lines to get a list of the tests using them:
if 0: # pragma: debugging
- pth = "/tmp/processes.txt"
- with open(pth, "a", encoding="utf-8") as proctxt: # type: ignore[unreachable]
+ pth = "/tmp/processes.txt" # type: ignore[unreachable]
+ with open(pth, "a", encoding="utf-8") as proctxt:
print(os.getenv("PYTEST_CURRENT_TEST", "unknown"), file=proctxt, flush=True)
encoding = os.device_encoding(1) or (
- locale.getdefaultencoding() if sys.version_info < (3, 10) else locale.getencoding()
+ locale.getpreferredencoding()
+ if sys.version_info < (3, 11)
+ else locale.getencoding() # type: ignore
)
# In some strange cases (PyPy3 in a virtualenv!?) the stdout encoding of
diff --git a/tox.ini b/tox.ini
index e0c5dbee..dbc0f1f9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -28,7 +28,14 @@ setenv =
pypy3{,9,10,11}: COVERAGE_TEST_CORES=pytrace
# If we ever need a stronger way to suppress warnings:
#PYTHONWARNINGS=ignore:removed in Python 3.14; use ast.Constant:DeprecationWarning
- PYTHONWARNDEFAULTENCODING=1
+ # We want to know about missing encoding arguments, but we need to silence
+ # some warnings that aren't ours. We can't silence them in 3.9 because
+ # EncodingWarning doesn't exist yet, and it's hard to suppress them in some
+ # environments and not others. So by default, don't warn, and will enable
+ # the warning in a handful of environments to catch the problems.
+ PYTHONWARNDEFAULTENCODING=
+ py3{10,11,12,13,14}: PYTHONWARNDEFAULTENCODING=1
+ py3{10,11,12,13,14}: PYTHONWARNINGS=ignore::EncodingWarning:pip._internal.utils.subprocess
# Disable CPython's color output
PYTHON_COLORS=0 |
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Thanks! I have one more warning to suppress that I'll do on master after merging this. |
One more tweak is in commit 6999a4e. |
This is now released as part of coverage 7.8.1. |
Thanks! I can verify build's test suite now passes without warnings. |
This fixes #1966 by adding
encoding="utf-8"
everywhere. See https://peps.python.org/pep-0597/.