Skip to content

Commit

Permalink
Use pytest.ini to reduce EncodingWarning spam
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Mar 4, 2024
1 parent dbc6471 commit bb9e67c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
32 changes: 19 additions & 13 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,36 @@ 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
# Until Python 3.9 support is dropped, we can't use `encoding="locale"` directly,
# but we'd also prefer switching to `encoding="utf-8"` wherever possible
# in preparation of https://peps.python.org/pep-0686/
# In the mean time, it causes too much noise in tests
ignore:'encoding' argument not specified::setuptools
ignore:'encoding' argument not specified::pkg_resources

## upstream

# Ensure ResourceWarnings are emitted
default::ResourceWarning

# subprocess.check_output still warns with EncodingWarning even with encoding set
ignore:'encoding' argument not specified::setuptools.tests.environment

# 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

# pypa/distutils#236
ignore:'encoding' argument not specified::distutils

# https://github.com/pypa/setuptools/issues/1823
ignore:bdist_wininst command is deprecated
# Suppress this error; unimportant for CI tests
Expand Down Expand Up @@ -68,11 +79,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 @@ -538,7 +538,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()``).
"""
encoding = "locale" if sys.version_info >= (3, 10) else None
with io.BytesIO() as buffer:
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 bb9e67c

Please sign in to comment.