Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/4255.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Treat ``EncodingWarning``s as errors in tests. -- by :user:`Avasam`
28 changes: 16 additions & 12 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,31 @@ 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+

## upstream

# Ensure ResourceWarnings are emitted
default::ResourceWarning

# python/mypy#17057
ignore:'encoding' argument not specified::mypy
ignore:'encoding' argument not specified::configparser
# ^-- ConfigParser is called by mypy,
# but ignoring the warning in `mypy` is not enough
# to make it work on PyPy
Comment thread
Avasam marked this conversation as resolved.

# realpython/pytest-mypy#152
ignore:'encoding' argument not specified::pytest_mypy
Comment thread
Avasam marked this conversation as resolved.

# python/cpython#100750
ignore:'encoding' argument not specified::platform
# TODO: Set encoding when openning/writing tmpdir files with pytest's LocalPath.open
# see pypa/setuptools#4326
ignore:'encoding' argument not specified::_pytest

# pypa/build#615
ignore:'encoding' argument not specified::build.env

# dateutil/dateutil#1284
ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning:dateutil.tz.tz
# Already fixed in pypa/distutils, but present in stdlib
ignore:'encoding' argument not specified::distutils

## end upstream

Expand Down Expand Up @@ -69,11 +78,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 @@ -565,7 +565,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")
2 changes: 1 addition & 1 deletion setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def run():
# to obtain a distribution object first, and then run the distutils
# commands later, because these files will be removed in the meantime.

with open('world.py', 'w') as f:
with open('world.py', 'w', encoding="utf-8") as f:
f.write('x = 42')

try:
Expand Down
13 changes: 13 additions & 0 deletions setuptools/tests/test_build_py.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import stat
import shutil
import warnings
from pathlib import Path
from unittest.mock import Mock

Expand Down Expand Up @@ -162,11 +163,23 @@ def test_excluded_subpackages(tmpdir_cwd):
dist.parse_config_files()

build_py = dist.get_command_obj("build_py")

msg = r"Python recognizes 'mypkg\.tests' as an importable package"
with pytest.warns(SetuptoolsDeprecationWarning, match=msg):
# TODO: To fix #3260 we need some transition period to deprecate the
# existing behavior of `include_package_data`. After the transition, we
# should remove the warning and fix the behaviour.

if os.getenv("SETUPTOOLS_USE_DISTUTILS") == "stdlib":
# pytest.warns reset the warning filter temporarily
# https://github.com/pytest-dev/pytest/issues/4011#issuecomment-423494810
warnings.filterwarnings(
"ignore",
"'encoding' argument not specified",
module="distutils.text_file",
# This warning is already fixed in pypa/distutils but not in stdlib
)

build_py.finalize_options()
build_py.run()

Expand Down
14 changes: 12 additions & 2 deletions setuptools/tests/test_windows_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def test_basic(self, tmpdir):
'arg5 a\\\\b',
]
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, text=True
cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
text=True,
encoding="utf-8",
)
stdout, stderr = proc.communicate('hello\nworld\n')
actual = stdout.replace('\r\n', '\n')
Expand Down Expand Up @@ -143,7 +147,11 @@ def test_symlink(self, tmpdir):
'arg5 a\\\\b',
]
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, text=True
cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
text=True,
encoding="utf-8",
)
stdout, stderr = proc.communicate('hello\nworld\n')
actual = stdout.replace('\r\n', '\n')
Expand Down Expand Up @@ -191,6 +199,7 @@ def test_with_options(self, tmpdir):
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
)
stdout, stderr = proc.communicate()
actual = stdout.replace('\r\n', '\n')
Expand Down Expand Up @@ -240,6 +249,7 @@ def test_basic(self, tmpdir):
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
)
stdout, stderr = proc.communicate()
assert not stdout
Expand Down