Skip to content

Commit 63dda17

Browse files
committed
Update pytest.ini for EncodingWarning from external libraries
+ avoid getpreferredencoding when possible
1 parent 965636e commit 63dda17

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

pytest.ini

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ 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+
17+
# pypa/distutils#236
18+
ignore:'encoding' argument not specified::distutils
19+
ignore:'encoding' argument not specified::setuptools._distutils
20+
21+
# subprocess.check_output still warns with EncodingWarning even with encoding set
22+
ignore:'encoding' argument not specified::setuptools.tests.environment
23+
1224
## upstream
1325

1426
# Ensure ResourceWarnings are emitted
@@ -17,14 +29,8 @@ filterwarnings=
1729
# realpython/pytest-mypy#152
1830
ignore:'encoding' argument not specified::pytest_mypy
1931

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
32+
# pytest-dev/pytest # TODO: Raise issue upstream
33+
ignore:'encoding' argument not specified::_pytest
2834

2935
## end upstream
3036

@@ -68,11 +74,6 @@ filterwarnings=
6874
# https://github.com/pypa/setuptools/issues/3655
6975
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning
7076

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-
7677
# Avoid errors when testing pkg_resources.declare_namespace
7778
ignore:.*pkg_resources\.declare_namespace.*:DeprecationWarning
7879

setuptools/command/editable_wheel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ def _encode_pth(content: str) -> bytes:
556556
This function tries to simulate this behaviour without having to create an
557557
actual file, in a way that supports a range of active Python versions.
558558
(There seems to be some variety in the way different version of Python handle
559-
``encoding=None``, not all of them use ``locale.getpreferredencoding(False)``).
559+
``encoding=None``, not all of them use ``locale.getpreferredencoding(False)``
560+
or ``locale.getencoding()``).
560561
"""
561562
with io.BytesIO() as buffer:
562563
wrapper = io.TextIOWrapper(buffer, encoding=py39.LOCALE_ENCODING)

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)