Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[debt] EncodingWarning when using pytest's tmpdir.join(...).write(...) #4326

Open
abravalheri opened this issue Apr 24, 2024 · 2 comments
Open

Comments

@abravalheri
Copy link
Contributor

In the last CI tests we can see the following warnings:

setuptools/tests/config/test_setupcfg.py: 54 warnings
setuptools/tests/test_bdist_egg.py: 2 warnings
setuptools/tests/test_dist.py: 1 warning
setuptools/tests/test_easy_install.py: 1 warning
setuptools/tests/test_setuptools.py: 2 warnings
setuptools/tests/test_packageindex.py: 1 warning
setuptools/tests/test_virtualenv.py: 1 warning
  /home/runner/work/setuptools/setuptools/.tox/py/lib/python3.11/site-packages/_pytest/_py/error.py:87: EncodingWarning: 'encoding' argument not specified
    return func(*args, **kwargs)

This seems to came from the fact that we are using tmpdir.join(...)write(...).
This method does not allow to specify the encoding argument.

We could replace it with write_text(..., encoding="utf-8").
However the tmpdir fixture itself is deprecated, so another possibility would be moving to tmp_dir.

Part of #3810.

@abravalheri
Copy link
Contributor Author

Since tmpdir is a legacy API and there is already support for encoding in write_text(), I think it is unlikely this will change upstream.

@Avasam
Copy link
Contributor

Avasam commented Apr 24, 2024

LocalPath.open and LocalPath.write_text both support setting an encoding.
The only advantage of write over write_text, is that in non-b mode it'll automatically stringify the data.
https://github.com/pytest-dev/pytest/blob/main/src/_pytest/_py/path.py#L903

So we have two paths forward:

  1. Update the fixture (should probably be done anyway)
  2. Change write for write_text and add encoding where it's still missing.

Either way, I've added a todo comment in #4255

(note: small typos in issue title: "debit" --> "debt", and missing . before "write")

@abravalheri abravalheri changed the title [debit] EncodingWarning when using pytest's tmpdir.join(...)write(...) [debt] EncodingWarning when using pytest's tmpdir.join(...).write(...) Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants