From 63dda17644840997e08e254cdb03b916001194a8 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 8 Mar 2024 17:21:56 -0500 Subject: [PATCH] Update `pytest.ini` for `EncodingWarning` from external libraries + avoid getpreferredencoding when possible --- pytest.ini | 27 ++++++++++++++------------- setuptools/command/editable_wheel.py | 3 ++- setuptools/tests/__init__.py | 9 +++++++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pytest.ini b/pytest.ini index 1ef3fc73c29..351940f426a 100644 --- a/pytest.ini +++ b/pytest.ini @@ -9,6 +9,18 @@ filterwarnings= # Fail on warnings error + # Workarounds for pypa/setuptools#3810 + # Can't use EncodingWarning as it doesn't exist on Python 3.9. + # These warnings only appear on Python 3.10+ + default:'encoding' argument not specified + + # pypa/distutils#236 + ignore:'encoding' argument not specified::distutils + ignore:'encoding' argument not specified::setuptools._distutils + + # subprocess.check_output still warns with EncodingWarning even with encoding set + ignore:'encoding' argument not specified::setuptools.tests.environment + ## upstream # Ensure ResourceWarnings are emitted @@ -17,14 +29,8 @@ filterwarnings= # realpython/pytest-mypy#152 ignore:'encoding' argument not specified::pytest_mypy - # python/cpython#100750 - ignore:'encoding' argument not specified::platform - - # pypa/build#615 - ignore:'encoding' argument not specified::build.env - - # dateutil/dateutil#1284 - ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning:dateutil.tz.tz + # pytest-dev/pytest # TODO: Raise issue upstream + ignore:'encoding' argument not specified::_pytest ## end upstream @@ -68,11 +74,6 @@ filterwarnings= # https://github.com/pypa/setuptools/issues/3655 ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning - # Workarounds for pypa/setuptools#3810 - # Can't use EncodingWarning as it doesn't exist on Python 3.9 - default:'encoding' argument not specified - default:UTF-8 Mode affects locale.getpreferredencoding(). - # Avoid errors when testing pkg_resources.declare_namespace ignore:.*pkg_resources\.declare_namespace.*:DeprecationWarning diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index 5f08ab53fca..e2215246f8c 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -556,7 +556,8 @@ def _encode_pth(content: str) -> bytes: This function tries to simulate this behaviour without having to create an actual file, in a way that supports a range of active Python versions. (There seems to be some variety in the way different version of Python handle - ``encoding=None``, not all of them use ``locale.getpreferredencoding(False)``). + ``encoding=None``, not all of them use ``locale.getpreferredencoding(False)`` + or ``locale.getencoding()``). """ with io.BytesIO() as buffer: wrapper = io.TextIOWrapper(buffer, encoding=py39.LOCALE_ENCODING) diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py index 564adf2b0ae..738ebf43bef 100644 --- a/setuptools/tests/__init__.py +++ b/setuptools/tests/__init__.py @@ -1,10 +1,15 @@ import locale +import sys import pytest __all__ = ['fail_on_ascii'] - -is_ascii = locale.getpreferredencoding() == 'ANSI_X3.4-1968' +locale_encoding = ( + locale.getencoding() + if sys.version_info >= (3, 11) + else locale.getpreferredencoding(False) +) +is_ascii = locale_encoding == 'ANSI_X3.4-1968' fail_on_ascii = pytest.mark.xfail(is_ascii, reason="Test fails in this locale")