Skip to content

EncodingWarning raised in cacheprovider #9910

@AA-Turner

Description

@AA-Turner

Sphinx recently enabled the EncodingWarning feature of Python 3.10+ in tests.12

PyTest reports three EncodingWarnings in _pytest/cacheprovider.py, output below:

.tox/du18/lib/python3.10/site-packages/_pytest/cacheprovider.py:199
  /home/runner/work/sphinx/sphinx/.tox/du18/lib/python3.10/site-packages/_pytest/cacheprovider.py:199: EncodingWarning: 'encoding' argument not specified
    readme_path.write_text(README_CONTENT)

.tox/du18/lib/python3.10/site-packages/_pytest/cacheprovider.py:189
.tox/du18/lib/python3.10/site-packages/_pytest/cacheprovider.py:189
  /home/runner/work/sphinx/sphinx/.tox/du18/lib/python3.10/site-packages/_pytest/cacheprovider.py:189: EncodingWarning: 'encoding' argument not specified
    f = path.open("w")

.tox/du18/lib/python3.10/site-packages/_pytest/cacheprovider.py:160
  /home/runner/work/sphinx/sphinx/.tox/du18/lib/python3.10/site-packages/_pytest/cacheprovider.py:160: EncodingWarning: 'encoding' argument not specified
    with path.open("r") as f:

The remedy is to add an explicit encoding="..." argument, most likely "utf-8".

Reproducer is python -X warn_default_encoding -m pytest ... with a path to a test suite.

Test session preamble:

============================= test session starts ==============================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0 -- /home/runner/work/sphinx/sphinx/.tox/du18/bin/python
cachedir: .tox/du18/.pytest_cache
libraries: Sphinx-5.0.0+/7970e6c, docutils-0.18.1
base tempdir: /tmp/pytest-of-runner/pytest-0
rootdir: /home/runner/work/sphinx/sphinx, configfile: setup.cfg, testpaths: tests
plugins: cov-3.0.0

A

Footnotes

  1. https://docs.python.org/3/library/io.html#io-encoding-warning

  2. https://docs.python.org/3/using/cmdline.html?highlight=warn_default_encoding#cmdoption-X

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributorplugin: cacherelated to the cache builtin plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions