Skip to content

Commit

Permalink
Update pytest.ini for EncodingWarning from external libraries
Browse files Browse the repository at this point in the history
+ avoid getpreferredencoding when possible
  • Loading branch information
Avasam committed Mar 8, 2024
1 parent 965636e commit 63dda17
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
27 changes: 14 additions & 13 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions setuptools/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 63dda17

Please sign in to comment.