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_entry_points_by_index (test.test_importlib.test_metadata_api.APITests) fails on Fedora 33 and 34 #88617

Closed
hroncok mannequin opened this issue Jun 18, 2021 · 12 comments
Labels
3.10 only security fixes 3.11 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@hroncok
Copy link
Mannequin

hroncok mannequin commented Jun 18, 2021

BPO 44451
Nosy @jaraco, @hroncok, @miss-islington, @tirkarthi
PRs
  • bpo-44451: Reset DeprecationWarning filters in test_importlib.test_entry_points_by_index #26784
  • [3.10] bpo-44451: Reset DeprecationWarning filters in test_importlib.test_entry_points_by_index (GH-26784) #26790
  • 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 2021-06-18.20:25:20.873>
    created_at = <Date 2021-06-18.12:08:37.871>
    labels = ['type-bug', 'tests', '3.10', '3.11']
    title = 'test_entry_points_by_index (test.test_importlib.test_metadata_api.APITests) fails on Fedora 33 and 34'
    updated_at = <Date 2021-06-18.20:31:09.773>
    user = 'https://github.com/hroncok'

    bugs.python.org fields:

    activity = <Date 2021-06-18.20:31:09.773>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-06-18.20:25:20.873>
    closer = 'jaraco'
    components = ['Tests']
    creation = <Date 2021-06-18.12:08:37.871>
    creator = 'hroncok'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44451
    keywords = ['patch']
    message_count = 12.0
    messages = ['396051', '396052', '396054', '396055', '396057', '396059', '396060', '396062', '396063', '396082', '396084', '396085']
    nosy_count = 4.0
    nosy_names = ['jaraco', 'hroncok', 'miss-islington', 'xtreak']
    pr_nums = ['26784', '26790']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue44451'
    versions = ['Python 3.10', 'Python 3.11']

    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Jun 18, 2021

    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

    @hroncok hroncok mannequin added stdlib Python modules in the Lib dir 3.10 only security fixes type-bug An unexpected behavior, bug, or error labels Jun 18, 2021
    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Jun 18, 2021

    Also reproduced on the main branch.

    @hroncok hroncok mannequin added 3.11 only security fixes labels Jun 18, 2021
    @tirkarthi
    Copy link
    Member

    This seems to have been reported also at https://bugs.python.org/issue44246#msg395202

    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Jun 18, 2021

    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

    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Jun 18, 2021

    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.

    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Jun 18, 2021

    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)

    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Jun 18, 2021

    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.

    @hroncok hroncok mannequin added tests Tests in the Lib/test dir and removed stdlib Python modules in the Lib dir labels Jun 18, 2021
    @jaraco
    Copy link
    Member

    jaraco commented Jun 18, 2021

    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.

    @jaraco jaraco added stdlib Python modules in the Lib dir and removed tests Tests in the Lib/test dir labels Jun 18, 2021
    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Jun 18, 2021

    Submitted to both.

    #26784
    python/importlib_metadata#325

    @hroncok hroncok mannequin added tests Tests in the Lib/test dir and removed stdlib Python modules in the Lib dir labels Jun 18, 2021
    @jaraco
    Copy link
    Member

    jaraco commented Jun 18, 2021

    New changeset df1502e by Miro Hrončok in branch 'main':
    bpo-44451: Reset DeprecationWarning filters in test_importlib.test_entry_points_by_index (GH-26784)
    df1502e

    @jaraco
    Copy link
    Member

    jaraco commented Jun 18, 2021

    Big thanks Miro for the detailed work on this matter.

    @jaraco jaraco closed this as completed Jun 18, 2021
    @jaraco jaraco closed this as completed Jun 18, 2021
    @miss-islington
    Copy link
    Contributor

    New changeset bf55a79 by Miss Islington (bot) in branch '3.10':
    bpo-44451: Reset DeprecationWarning filters in test_importlib.test_entry_points_by_index (GH-26784)
    bf55a79

    @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 3.11 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants