classification
Title: test_entry_points_by_index (test.test_importlib.test_metadata_api.APITests) fails on Fedora 33 and 34
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: hroncok, jaraco, miss-islington, xtreak
Priority: normal Keywords: patch

Created on 2021-06-18 12:08 by hroncok, last changed 2021-06-18 20:31 by miss-islington. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26784 merged hroncok, 2021-06-18 13:20
PR 26790 merged miss-islington, 2021-06-18 20:02
Messages (12)
msg396051 - (view) Author: Miro Hrončok (hroncok) * Date: 2021-06-18 12:08
Hello.

When we attempted to upgrade to Python 3.10.0b3 on Fedora 33 and 34, we see the following test failure:



======================================================================
ERROR: test_entry_points_by_index (test.test_importlib.test_metadata_api.APITests)
Prior versions of Distribution.entry_points would return a
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.10.0b3/Lib/test/test_importlib/test_metadata_api.py", line 145, in test_entry_points_by_index
    expected = next(iter(caught))
StopIteration
----------------------------------------------------------------------
Ran 1402 tests in 2.125s
FAILED (errors=1, skipped=18, expected failures=1)


I've reproduced it without any Fedora's patches:

$ cd cpython
$ git switch -d v3.10.0b3  # or the tip of 3.10 today, 77eaf14d27

$ ./configure --enable-shared && make

$ LD_LIBRARY_PATH=. ./python -m test test_importlib
0:00:00 load avg: 13.59 Run tests sequentially
0:00:00 load avg: 13.59 [1/1] test_importlib
test test_importlib failed -- Traceback (most recent call last):
  File "/home/churchyard/Dokumenty/RedHat/cpython/Lib/test/test_importlib/test_metadata_api.py", line 145, in test_entry_points_by_index
    expected = next(iter(caught))
StopIteration

test_importlib failed

== Tests result: FAILURE ==

1 test failed:
    test_importlib

Total duration: 11.0 sec
Tests result: FAILURE
msg396052 - (view) Author: Miro Hrončok (hroncok) * Date: 2021-06-18 12:12
Also reproduced on the main branch.
msg396054 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2021-06-18 12:18
This seems to have been reported also at https://bugs.python.org/issue44246#msg395202
msg396055 - (view) Author: Miro Hrončok (hroncok) * Date: 2021-06-18 12:21
Also reproducible without --enable-shared.

[cpython (main)]$ ./configure && make
[cpython (main)]$ ./python --version
Python 3.11.0a0

[cpython (main)]$ ./python -m test test_importlib
0:00:00 load avg: 5.40 Run tests sequentially
0:00:00 load avg: 5.40 [1/1] test_importlib
test test_importlib failed -- Traceback (most recent call last):
  File "/home/churchyard/Dokumenty/RedHat/cpython/Lib/test/test_importlib/test_metadata_api.py", line 145, in test_entry_points_by_index
    expected = next(iter(caught))
StopIteration

test_importlib failed

== Tests result: FAILURE ==

1 test failed:
    test_importlib

Total duration: 3.5 sec
Tests result: FAILURE
msg396057 - (view) Author: Miro Hrončok (hroncok) * Date: 2021-06-18 12:36
I get the DeprecationWarning the tests assumes when not running via the test:

$ cat distinfo_pkg-1.0.0.dist-info/entry_points.txt 
[entries]
main = mod:main
ns:sub = mod:main

$ ./python
Python 3.11.0a0 (heads/main:0982ded179, Jun 18 2021, 14:14:16) [GCC 10.3.1 20210422 (Red Hat 10.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys
>>> sys.path.insert(0, os.path.abspath('.'))
>>> from importlib.metadata import distribution
>>> distribution('distinfo-pkg')
<importlib.metadata.PathDistribution object at 0x7f1796d8bcd0>
>>> eps = distribution('distinfo-pkg').entry_points
>>> eps[0]
<stdin>:1: DeprecationWarning: Accessing entry points by index is deprecated. Cast to tuple if needed.
EntryPoint(name='main', value='mod:main', group='entries')


Not sure why I don't get it in the test yet.
msg396059 - (view) Author: Miro Hrončok (hroncok) * Date: 2021-06-18 13:10
I've added warnings.resetwarnings() to the test. it makes it pass.

It says:


Warning -- warnings.filters was modified by test_importlib
  Before: (140568295281984, [('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)], [('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)])
  After:  (140568295281984, [('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)], []) 
test_importlib failed (env changed)
msg396060 - (view) Author: Miro Hrončok (hroncok) * Date: 2021-06-18 13:14
Adding the reset to the context manager:

        with warnings.catch_warnings(record=True) as caught:
            warnings.resetwarnings()
            eps[0]

Or even better explicitly:

        with warnings.catch_warnings(record=True) as caught:
            warnings.filterwarnings("default", category=DeprecationWarning)
            eps[0]

Makes it pass and makes the tests framework happy. I still don't understand why it is filtered, but other tests in the file (e.g. test_entry_points_dict_construction) already o this, so I will submit a pull request.
msg396062 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2021-06-18 13:20
Other tests reset the filters? Good observation. I’d missed that detail. If it’s easier to submit a PR to importlib_metadata, feel free to do that as I’ll want the change in both places.
msg396063 - (view) Author: Miro Hrončok (hroncok) * Date: 2021-06-18 13:28
Submitted to both.

https://github.com/python/cpython/pull/26784
https://github.com/python/importlib_metadata/pull/325
msg396082 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2021-06-18 20:02
New changeset df1502e47fc1e0cf1e7d460ae04530c3e2e4a7c6 by Miro Hrončok in branch 'main':
bpo-44451: Reset DeprecationWarning filters in test_importlib.test_entry_points_by_index (GH-26784)
https://github.com/python/cpython/commit/df1502e47fc1e0cf1e7d460ae04530c3e2e4a7c6
msg396084 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2021-06-18 20:25
Big thanks Miro for the detailed work on this matter.
msg396085 - (view) Author: miss-islington (miss-islington) Date: 2021-06-18 20:31
New changeset bf55a799e0c19285b094d71f794c301c1afaa28d by Miss Islington (bot) in branch '3.10':
bpo-44451: Reset DeprecationWarning filters in test_importlib.test_entry_points_by_index (GH-26784)
https://github.com/python/cpython/commit/bf55a799e0c19285b094d71f794c301c1afaa28d
History
Date User Action Args
2021-06-18 20:31:09miss-islingtonsetmessages: + msg396085
2021-06-18 20:25:20jaracosetstatus: open -> closed
resolution: fixed
messages: + msg396084

stage: patch review -> resolved
2021-06-18 20:02:56miss-islingtonsetnosy: + miss-islington

pull_requests: + pull_request25374
stage: patch review
2021-06-18 20:02:53jaracosetmessages: + msg396082
2021-06-18 13:28:50hroncoksetmessages: + msg396063
components: + Tests, - Library (Lib)
2021-06-18 13:20:44jaracosetmessages: + msg396062
components: + Library (Lib), - Tests
stage: patch review -> (no value)
2021-06-18 13:20:21hroncoksetkeywords: + patch
stage: patch review
pull_requests: + pull_request25369
2021-06-18 13:17:48hroncoksetcomponents: + Tests, - Library (Lib)
2021-06-18 13:14:55hroncoksetmessages: + msg396060
2021-06-18 13:10:24hroncoksetmessages: + msg396059
2021-06-18 12:36:13hroncoksetmessages: + msg396057
2021-06-18 12:21:51hroncoksetmessages: + msg396055
2021-06-18 12:18:08xtreaksetnosy: + xtreak
messages: + msg396054
2021-06-18 12:12:45hroncoksetmessages: + msg396052
versions: + Python 3.11
2021-06-18 12:08:37hroncokcreate