Skip to content

Problems with the warningregistry() decorator in Lib/unittest/test/test_loader.py #79133

Description

@serhiy-storchaka
BPO 34952
Nosy @warsaw, @rbtcollins, @ezio-melotti, @voidspace, @serhiy-storchaka

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 = None
created_at = <Date 2018-10-10.13:14:12.709>
labels = ['3.8', '3.7', 'tests']
title = 'Problems with the warningregistry() decorator in Lib/unittest/test/test_loader.py'
updated_at = <Date 2018-10-10.13:15:59.662>
user = 'https://github.com/serhiy-storchaka'

bugs.python.org fields:

activity = <Date 2018-10-10.13:15:59.662>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Tests']
creation = <Date 2018-10-10.13:14:12.709>
creator = 'serhiy.storchaka'
dependencies = []
files = []
hgrepos = []
issue_num = 34952
keywords = []
message_count = 2.0
messages = ['327468', '327469']
nosy_count = 5.0
nosy_names = ['barry', 'rbcollins', 'ezio.melotti', 'michael.foord', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue34952'
versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

Activity

  1. serhiy-storchaka commented on Oct 10, 2018

    @serhiy-storchaka
    MemberAuthor

    There are other issues in the warningregistry() decorator in Lib/unittest/test/test_loader.py.

    It contains a code:

        missing = []
        saved = getattr(warnings, '__warningregistry__', missing).copy()
        ...
        if saved is missing:

    The problem is that the condition saved is missing is always false. If warningregistry was absent, saved is missing.copy() which is a new empty list. As result, warnings.warningregistry is set to [] after the test if it did not exist before the test.

    Other problem is that this decorator works with __warningregistry__ in the warnings module. It is changed only when warnings are emitted by the code of the warnings module. Is it intentional? I don't know any code that emits warnings in the warnings module.

    It is hard to understand what was the intention of this decorator. From initial it was not working and cause the decorated tests be silently skipped. This was fixed in bpo-27063, but now I am not sure that it works as intended. Tests continue to pass after removing it.

  2. serhiy-storchaka commented on Oct 10, 2018

    @serhiy-storchaka
    MemberAuthor

    The decorator was added in bpo-16662.

  3. transferred this issue fromon Apr 10, 2022
  4. serhiy-storchaka commented on Aug 8, 2026

    @serhiy-storchaka
    MemberAuthor

    The warningregistry() decorator no longer exists. It was removed in c834c02 (GH-92556) together with the deprecated load_tests aliases whose deprecation warnings it was meant to contain, so both problems are moot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.7 (EOL)end of life3.8 (EOL)end of lifetestsTests in the Lib/test dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions