aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_unittest/testmock/testthreadingmock.py
Commit message (Collapse)AuthorAge
* gh-109653: Remove unused imports in the `Lib/` directory (#109803)Alex Waygood2023-09-24
|
* gh-61215: threadingmock: Improve test suite to avoid race conditions (#106822)Mario Corchero2023-07-17
| | | | | | | | threadingmock: Improve test suite to avoid race conditions Simplify tests and split them into multiple tests to prevent assertions from triggering race conditions. Additionally, we rely on calling the mocks without delay to validate the functionality of matching calls.
* Remove unused branches from mock module (#106617)Chris Withers2023-07-11
| | | | | | | * lambda has a name of __none__, but no async lambda so this branch is not needed * _get_signature_object only returns None for bound builtins. There are no async builtins so this branch isn't needed * Exclude a couple of methods from coverage checking in the downstream rolling backport of mock
* gh-106458: Mark `testthreadingmock.py` with `@requires_working_threading` ↵Mario Corchero2023-07-06
| | | | | | | (GH-106366) Mark `testthreadingmock.py` with `threading_helper.requires_working_threading`. Also add longer delays to reduce the change of a race conditions on the tests that validate short timeouts.
* gh-61215: Rename `wait_until_any_call` to `wait_until_any_call_with` (#106414)Mario Corchero2023-07-04
| | | | | | mock: Rename `wait_until_any_call` to `wait_until_any_call_with` Rename the method to be more explicit that it expects the args and kwargs to wait for.
* gh-61215: New mock to wait for multi-threaded events to happen (#16094)Mario Corchero2023-07-03
mock: Add `ThreadingMock` class Add a new class that allows to wait for a call to happen by using `Event` objects. This mock class can be used to test and validate expectations of multithreading code. It uses two attributes for events to distinguish calls with any argument and calls with specific arguments. The calls with specific arguments need a lock to prevent two calls in parallel from creating the same event twice. The timeout is configured at class and constructor level to allow users to set a timeout, we considered passing it as an argument to the function but it could collide with a function parameter. Alternatively we also considered passing it as positional only but from an API caller perspective it was unclear what the first number meant on the function call, think `mock.wait_until_called(1, "arg1", "arg2")`, where 1 is the timeout. Lastly we also considered adding the new attributes to magic mock directly rather than having a custom mock class for multi threading scenarios, but we preferred to have specialised class that can be composed if necessary. Additionally, having added it to `MagicMock` directly would have resulted in `AsyncMock` having this logic, which would not work as expected, since when if user "waits" on a coroutine does not have the same meaning as waiting on a standard call. Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>