Skip to content

Notify ThreadingMock waiters before running side effects #159344

Description

@esadomer

A ThreadingMock call is recorded even when its side effect raises, but the wait APIs still time out because their events are only set after successful completion of the side effect. The same ordering prevents a side effect from waiting on its own recorded call.

Reproducer, run with the interpreter built from the CPython checkout:

from unittest.mock import ThreadingMock

mock = ThreadingMock(side_effect=ValueError, timeout=0)
try:
    mock(1, key=2)
except ValueError:
    pass
mock.assert_called_once_with(1, key=2)
mock.wait_until_called()
mock.wait_until_any_call_with(1, key=2)

Expected: Both waits recognize the recorded call.

Observed: wait_until_called() raises AssertionError indicating the mock was not called before the timeout.

Environment: CPython main, Windows debug build.

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    testsTests in the Lib/test dir
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    and removed
    type-featureA feature request or enhancement
    testsTests in the Lib/test dir
    on Oct 14, 2026
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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions