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

Fix ResourceWarning due to unclosed file resource. #274

Merged
merged 2 commits into from
Dec 6, 2022
Merged

Fix ResourceWarning due to unclosed file resource. #274

merged 2 commits into from
Dec 6, 2022

Conversation

tirkarthi
Copy link
Member

Fixes below warnings that were originally found in CPython test suite.

============================================================================= warnings summary ==============================================================================
importlib_resources/tests/test_resource.py::ResourceFromZipsTest01::test_as_file_directory
  /home/karthikeyan/stuff/python/importlib_resources/importlib_resources/_common.py:206: ResourceWarning: unclosed file <_io.BufferedWriter name='/tmp/tmpekn15a6u/ziptestdata/utf-16.file'>
    child.open('wb').write(source.read_bytes())
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

importlib_resources/tests/test_resource.py::ResourceFromZipsTest01::test_as_file_directory
  /home/karthikeyan/stuff/python/importlib_resources/importlib_resources/_common.py:206: ResourceWarning: unclosed file <_io.BufferedWriter name='/tmp/tmpekn15a6u/ziptestdata/utf-8.file'>
    child.open('wb').write(source.read_bytes())
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

importlib_resources/tests/test_resource.py::ResourceFromZipsTest01::test_as_file_directory
  /home/karthikeyan/stuff/python/importlib_resources/importlib_resources/_common.py:206: ResourceWarning: unclosed file <_io.BufferedWriter name='/tmp/tmpekn15a6u/ziptestdata/__init__.py'>
    child.open('wb').write(source.read_bytes())
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

importlib_resources/tests/test_resource.py::ResourceFromZipsTest01::test_as_file_directory
  /home/karthikeyan/stuff/python/importlib_resources/importlib_resources/_common.py:206: ResourceWarning: unclosed file <_io.BufferedWriter name='/tmp/tmpekn15a6u/ziptestdata/binary.file'>
    child.open('wb').write(source.read_bytes())
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

importlib_resources/tests/test_resource.py::ResourceFromZipsTest01::test_as_file_directory
  /home/karthikeyan/stuff/python/importlib_resources/importlib_resources/_common.py:206: ResourceWarning: unclosed file <_io.BufferedWriter name='/tmp/tmpekn15a6u/ziptestdata/subdirectory/__init__.py'>
    child.open('wb').write(source.read_bytes())
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

importlib_resources/tests/test_resource.py::ResourceFromZipsTest01::test_as_file_directory
  /home/karthikeyan/stuff/python/importlib_resources/importlib_resources/_common.py:206: ResourceWarning: unclosed file <_io.BufferedWriter name='/tmp/tmpekn15a6u/ziptestdata/subdirectory/binary.file'>
    child.open('wb').write(source.read_bytes())
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

@jaraco
Copy link
Member

jaraco commented Dec 6, 2022

I wonder why this test suite doesn't emit the warnings. Aah. So it seems Python ignores ResourceWarnings by default. I've opened jaraco/skeleton#73 to ensure this issue doesn't occur in any other skeleton-backed projects.

@jaraco jaraco merged commit b14f9b5 into python:main Dec 6, 2022
@jaraco
Copy link
Member

jaraco commented Dec 6, 2022

Released as v5.10.1. Will get synced with CPython in the future. I'll try not to let it linger into 2023.

@tirkarthi
Copy link
Member Author

Thanks @jaraco

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

Successfully merging this pull request may close these issues.

2 participants