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

test_importlib logs ResourceWarning: test_path.CommonTests.test_importing_module_as_side_effect() #85179

Closed
vstinner opened this issue Jun 17, 2020 · 4 comments
Labels
3.10 only security fixes tests Tests in the Lib/test dir

Comments

@vstinner
Copy link
Member

BPO 41007
Nosy @vstinner, @srinivasreddy

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-07-01.17:04:22.617>
created_at = <Date 2020-06-17.14:33:20.919>
labels = ['tests', '3.10']
title = 'test_importlib logs ResourceWarning: test_path.CommonTests.test_importing_module_as_side_effect()'
updated_at = <Date 2020-07-01.17:04:22.616>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2020-07-01.17:04:22.616>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2020-07-01.17:04:22.617>
closer = 'vstinner'
components = ['Tests']
creation = <Date 2020-06-17.14:33:20.919>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 41007
keywords = []
message_count = 4.0
messages = ['371743', '372761', '372762', '372770']
nosy_count = 2.0
nosy_names = ['vstinner', 'thatiparthy']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue41007'
versions = ['Python 3.10']

@vstinner
Copy link
Member Author

It seems like the issue was introduced in bpo-39791 by:

commit 843c277
Author: Jason R. Coombs <jaraco@jaraco.com>
Date: Sun Jun 7 21:00:51 2020 -0400

bpo-39791 native hooks for importlib.resources.files (GH-20576)

The warning:

$ ./python -X tracemalloc=20 -m test  test_importlib -m test.test_importlib.test_path.CommonTests.test_importing_module_as_side_effect -v
== CPython 3.10.0a0 (heads/importlib_typing:d1b0d052cf, Jun 17 2020, 16:09:52) [GCC 10.1.1 20200507 (Red Hat 10.1.1-1)]
== Linux-5.6.18-300.fc32.x86_64-x86_64-with-glibc2.31 little-endian
== cwd: /home/vstinner/python/master/build/test_python_67972
== CPU count: 8
== encodings: locale=UTF-8, FS=utf-8
0:00:00 load avg: 0.44 Run tests sequentially
0:00:00 load avg: 0.44 [1/1] test_importlib
test_importing_module_as_side_effect (test.test_importlib.test_path.CommonTests) ... /home/vstinner/python/master/Lib/contextlib.py:124: ResourceWarning: unclosed file <_io.BufferedReader name='/home/vstinner/python/master/Lib/test/test_importlib/data01/utf-8.file'>
  next(self.gen)
Object allocated at (most recent call last):
  File "/home/vstinner/python/master/Lib/unittest/runner.py", lineno 176
    test(result)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 84
    return self.run(*args, **kwds)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 122
    test(result)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 84
    return self.run(*args, **kwds)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 122
    test(result)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 84
    return self.run(*args, **kwds)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 122
    test(result)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 84
    return self.run(*args, **kwds)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 122
    test(result)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 84
    return self.run(*args, **kwds)
  File "/home/vstinner/python/master/Lib/unittest/suite.py", lineno 122
    test(result)
  File "/home/vstinner/python/master/Lib/unittest/case.py", lineno 653
    return self.run(*args, **kwds)
  File "/home/vstinner/python/master/Lib/unittest/case.py", lineno 593
    self._callTestMethod(testMethod)
  File "/home/vstinner/python/master/Lib/unittest/case.py", lineno 550
    method()
  File "/home/vstinner/python/master/Lib/test/test_importlib/util.py", lineno 509
    self.execute(data01.__name__, 'utf-8.file')
  File "/home/vstinner/python/master/Lib/test/test_importlib/test_path.py", lineno 10
    with resources.path(package, path):
  File "/home/vstinner/python/master/Lib/contextlib.py", lineno 117
    return next(self.gen)
  File "/home/vstinner/python/master/Lib/importlib/resources.py", lineno 118
    opener_reader = reader.open_resource(norm_resource)
  File "/home/vstinner/python/master/Lib/importlib/abc.py", lineno 465
    return self.files().joinpath(resource).open('rb')
  File "/home/vstinner/python/master/Lib/pathlib.py", lineno 1238
    return io.open(self, mode, buffering, encoding, errors, newline,
ok

Ran 1 test in 0.134s

OK

== Tests result: SUCCESS ==

1 test OK.

Total duration: 6.2 sec
Tests result: SUCCESS

@vstinner vstinner added 3.10 only security fixes tests Tests in the Lib/test dir labels Jun 17, 2020
@srinivasreddy
Copy link
Mannequin

srinivasreddy mannequin commented Jul 1, 2020

I can repro on 843c277 but I have tried this on latest master d0981e6 and I do not see the warning.

can be closed?

@srinivasreddy
Copy link
Mannequin

srinivasreddy mannequin commented Jul 1, 2020

(allhub) ➜ cpython git:(master) ✗ ./python.exe -X tracemalloc=20 -m test test_importlib -m test.test_importlib.test_path.CommonTests.test_importing_module_as_side_effect -v
== CPython 3.10.0a0 (heads/master:d0981e61a5, Jul 1 2020, 21:25:34) [Clang 11.0.3 (clang-1103.0.32.62)]
== macOS-10.15.5-x86_64-i386-64bit little-endian
== cwd: /Users/srini/workspace/consulting/cpython/build/test_python_1601æ
== CPU count: 12
== encodings: locale=UTF-8, FS=utf-8
0:00:00 load avg: 2.06 Run tests sequentially
0:00:00 load avg: 2.06 [1/1] test_importlib
test_importing_module_as_side_effect (test.test_importlib.test_path.CommonTests) ... ok

----------------------------------------------------------------------

Ran 1 test in 0.061s

OK

== Tests result: SUCCESS ==

1 test OK.

Total duration: 6.5 sec
Tests result: SUCCESS

@vstinner
Copy link
Member Author

vstinner commented Jul 1, 2020

Alright, this issue was fixed by:

commit 2fb5f03 (HEAD)
Author: Jason R. Coombs <jaraco@jaraco.com>
Date: Mon Jun 29 16:59:22 2020 -0400

bpo-40924: Ensure importlib.resources.path returns an extant path (GH-20857)

@vstinner vstinner closed this as completed Jul 1, 2020
@vstinner vstinner closed this as completed Jul 1, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes tests Tests in the Lib/test dir
Projects
None yet
Development

No branches or pull requests

1 participant