Skip to content

Commit bb9e67c

Browse files
committed
Use pytest.ini to reduce EncodingWarning spam
1 parent dbc6471 commit bb9e67c

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

pytest.ini

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,36 @@ filterwarnings=
99
# Fail on warnings
1010
error
1111

12+
# Workarounds for pypa/setuptools#3810
13+
# Can't use EncodingWarning as it doesn't exist on Python 3.9.
14+
# These warnings only appear on Python 3.10+
15+
default:'encoding' argument not specified
16+
# Until Python 3.9 support is dropped, we can't use `encoding="locale"` directly,
17+
# but we'd also prefer switching to `encoding="utf-8"` wherever possible
18+
# in preparation of https://peps.python.org/pep-0686/
19+
# In the mean time, it causes too much noise in tests
20+
ignore:'encoding' argument not specified::setuptools
21+
ignore:'encoding' argument not specified::pkg_resources
22+
1223
## upstream
1324

1425
# Ensure ResourceWarnings are emitted
1526
default::ResourceWarning
1627

28+
# subprocess.check_output still warns with EncodingWarning even with encoding set
29+
ignore:'encoding' argument not specified::setuptools.tests.environment
30+
1731
# realpython/pytest-mypy#152
1832
ignore:'encoding' argument not specified::pytest_mypy
1933

20-
# python/cpython#100750
21-
ignore:'encoding' argument not specified::platform
22-
23-
# pypa/build#615
24-
ignore:'encoding' argument not specified::build.env
25-
26-
# dateutil/dateutil#1284
27-
ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning:dateutil.tz.tz
34+
# pytest-dev/pytest # TODO: Raise issue upstream
35+
ignore:'encoding' argument not specified::_pytest
2836

2937
## end upstream
3038

39+
# pypa/distutils#236
40+
ignore:'encoding' argument not specified::distutils
41+
3142
# https://github.com/pypa/setuptools/issues/1823
3243
ignore:bdist_wininst command is deprecated
3344
# Suppress this error; unimportant for CI tests
@@ -68,11 +79,6 @@ filterwarnings=
6879
# https://github.com/pypa/setuptools/issues/3655
6980
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning
7081

71-
# Workarounds for pypa/setuptools#3810
72-
# Can't use EncodingWarning as it doesn't exist on Python 3.9
73-
default:'encoding' argument not specified
74-
default:UTF-8 Mode affects locale.getpreferredencoding().
75-
7682
# Avoid errors when testing pkg_resources.declare_namespace
7783
ignore:.*pkg_resources\.declare_namespace.*:DeprecationWarning
7884

setuptools/command/editable_wheel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ def _encode_pth(content: str) -> bytes:
538538
This function tries to simulate this behaviour without having to create an
539539
actual file, in a way that supports a range of active Python versions.
540540
(There seems to be some variety in the way different version of Python handle
541-
``encoding=None``, not all of them use ``locale.getpreferredencoding(False)``).
541+
``encoding=None``, not all of them use ``locale.getpreferredencoding(False)``
542+
or ``locale.getencoding()``).
542543
"""
543544
encoding = "locale" if sys.version_info >= (3, 10) else None
544545
with io.BytesIO() as buffer:

setuptools/tests/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import locale
2+
import sys
23

34
import pytest
45

56

67
__all__ = ['fail_on_ascii']
78

8-
9-
is_ascii = locale.getpreferredencoding() == 'ANSI_X3.4-1968'
9+
locale_encoding = (
10+
locale.getencoding()
11+
if sys.version_info >= (3, 11)
12+
else locale.getpreferredencoding(False)
13+
)
14+
is_ascii = locale_encoding == 'ANSI_X3.4-1968'
1015
fail_on_ascii = pytest.mark.xfail(is_ascii, reason="Test fails in this locale")

0 commit comments

Comments
 (0)