cpython/Lib/test/test_unittest
Mario Corchero d65b783b69
gh-61215: New mock to wait for multi-threaded events to happen (#16094)
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>
2023-07-03 07:56:54 +01:00
..
testmock gh-61215: New mock to wait for multi-threaded events to happen (#16094) 2023-07-03 07:56:54 +01:00
__init__.py
__main__.py
_test_warnings.py Revert "bpo-45162: Revert "Remove many old deprecated unittest features"" (GH-92556) 2022-06-26 10:18:06 +03:00
dummy.py
support.py bpo-4080: unittest durations (#12271) 2023-04-03 00:12:51 +02:00
test_assertions.py gh-68968: Correcting message display issue with assertEqual (#103937) 2023-05-04 16:37:17 -06:00
test_async_case.py Add more details in test_unittest (GH-99626) 2022-11-21 13:57:30 +02:00
test_break.py bpo-4080: unittest durations (#12271) 2023-04-03 00:12:51 +02:00
test_case.py gh-68968: Correcting message display issue with assertEqual (#103937) 2023-05-04 16:37:17 -06:00
test_discovery.py
test_functiontestcase.py
test_loader.py gh-104835: Remove unittest's deprecated getTestCaseNames, makeSuite, findTestCases (#104836) 2023-05-24 21:16:43 +00:00
test_program.py gh-62432: unittest runner: Exit code 5 if no tests were run (#102051) 2023-04-27 01:28:46 +00:00
test_result.py gh-105407: Remove unused imports in tests (#105408) 2023-06-06 22:50:43 +02:00
test_runner.py gh-62432: unittest runner: Exit code 5 if no tests were run (#102051) 2023-04-27 01:28:46 +00:00
test_setups.py
test_skipping.py
test_suite.py