Skip to content

EncodingWarnings raised (3) when using pyfakefs #957

Closed

Description

@jaraco

When running the distutils test suite, I see the following warnings:

distutils/tests/test_dist.py::TestDistributionBehavior::test_find_config_files_permission_error
  /Users/jaraco/code/pypa/distutils/.tox/py/lib/python3.12/site-packages/pyfakefs/fake_file.py:266: EncodingWarning: UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.
    self.encoding or locale.getpreferredencoding(False),

distutils/tests/test_dist.py::TestDistributionBehavior::test_find_config_files_permission_error
  /Users/jaraco/code/pypa/distutils/.tox/py/lib/python3.12/site-packages/pyfakefs/fake_file.py:748: EncodingWarning: UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.
    self._encoding = encoding or locale.getpreferredencoding(False)

distutils/tests/test_dist.py::TestDistributionBehavior::test_find_config_files_permission_error
  /Users/jaraco/code/pypa/distutils/.tox/py/lib/python3.12/site-packages/pyfakefs/helpers.py:409: EncodingWarning: 'encoding' argument not specified
    super().__init__(self._bytestream, encoding, errors, newline)

Activity

  1. mrbean-bremen commented on Mar 3, 2024

    @mrbean-bremen
    Member

    The first 2 warnings are trivial to fix, but as far as I can see, the third warning:

    distutils/tests/test_dist.py::TestDistributionBehavior::test_find_config_files_permission_error
      /Users/jaraco/code/pypa/distutils/.tox/py/lib/python3.12/site-packages/pyfakefs/helpers.py:409: EncodingWarning: 'encoding' argument not specified
        super().__init__(self._bytestream, encoding, errors, newline)
    

    comes from the client code:

     fake_home.joinpath(pydistutils_cfg).write_text('')

    write_text misses the encoding argument.

    @jaraco - can you confirm this?

  2. jaraco commented on Mar 3, 2024

    @jaraco
    Author

    Yes, that's right (confirmed in pypa/distutils@38b58a5b). I thought it might be something like that. I was unsure because the warning only gives the one location. I wonder if it's possible to alter the stacklevel or otherwise manipulate the warning in the __init__ wrapper, but I can't think of a way to do it. I also asked Gemini, and it also couldn't devise a general solution.

    I guess one solution could be to capture the warning in the init wrapper and then emit a new warning. Not sure it's worth it except to improve the discoverability for other users.

    Out of curiosity, how did you track it down?

  3. mrbean-bremen commented on Mar 3, 2024

    @mrbean-bremen
    Member

    Thanks for the fast response!

    I guess one solution could be to capture the warning in the init wrapper and then emit a new warning

    Well, that would be a possibility, but I'm reluctant to go that way. It would make the code more complicated for a questionable improvement.

    Out of curiosity, how did you track it down?

    That was easy - the warning message says where it comes from, and I just checked the respective code in disutils.
    Oh, and I also made sure to get the same warning in the real fs.

  4. added 3 commits that reference this issue on Mar 3, 2024
    02a4530
    657df33
    dd5d1af
  5. mrbean-bremen commented on Mar 3, 2024

    @mrbean-bremen
    Member

    Should be fixed in main now. Do you need a patch release?

  6. jaraco commented on Mar 3, 2024

    @jaraco
    Author

    Out of curiosity, how did you track it down?

    That was easy - the warning message says where it comes from, and I just checked the respective code in disutils. Oh, and I also made sure to get the same warning in the real fs.

    Oh! True. The output does mention the test that was being run. I didn't investigate it because I knew that in general the warning could have been triggered anywhere within that test (as part of setup/teardown or deep in the exercised behavior), but as it turns out, it was right there, so that makes sense.

    Agreed, probably not worth the hassle to try to surface those - but you may decide to revisit when these warnings surface for all users and not just those opting into the warnings early.

    I don't need a patch release. More important will be to have a notice here when the release is made so I can know to remove the warning exclusion.

  7. mrbean-bremen commented on Mar 3, 2024

    @mrbean-bremen
    Member

    you may decide to revisit when these warnings surface for all users and not just those opting into the warnings early

    Sure, if this pops up again, I will remember that ;)

    More important will be to have a notice here when the release is made so I can know to remove the warning exclusion.

    Sure, I'll let you know.

  8. mrbean-bremen commented on Apr 7, 2024

    @mrbean-bremen
    Member

    FYI: A new release is out.

  9. added a commit that references this issue on Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions