classification
Title: test_importlib logs ResourceWarning: test_path.CommonTests.test_importing_module_as_side_effect()
Type: Stage: resolved
Components: Tests Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: thatiparthy, vstinner
Priority: normal Keywords:

Created on 2020-06-17 14:33 by vstinner, last changed 2020-07-01 17:04 by vstinner. This issue is now closed.

Messages (4)
msg371743 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-17 14:33
It seems like the issue was introduced in bpo-39791 by:


commit 843c27765652e2322011fb3e5d88f4837de38c06
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
msg372761 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2020-07-01 16:10
I can repro on  843c27765652e2322011fb3e5d88f4837de38c06  but I have tried this on latest master d0981e6 and I do not see the warning. 

can be closed?
msg372762 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2020-07-01 16:10
(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
msg372770 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-07-01 17:04
Alright, this issue was fixed by:

commit 2fb5f038f2a2e91a7293d62dfd5601e6eb500c55 (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)
History
Date User Action Args
2020-07-01 17:04:22vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg372770

stage: resolved
2020-07-01 16:10:47thatiparthysetmessages: + msg372762
2020-07-01 16:10:07thatiparthysetnosy: + thatiparthy
messages: + msg372761
2020-06-17 14:33:20vstinnercreate