| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Spoke offline with @voidspace and suggested to keep this PR for the multithreading use case only as it is not trivial to get this working for multiprocess. It was also suggested to rename the mock to make it clear it is about multithreading and keep the Event as private as we are not exposing it anymore. @tirkarthi @voidspace @lisroach if this looks good I'll get started with the docs. |
Sorry, something went wrong.
|
Gentle ping @tirkarthi @voidspace @lisroach! Let me know if the general idea/naming looks good and I'll get to work on the documentation. |
Sorry, something went wrong.
|
Sorry, got caught up with new job. I will try to get to the PR after two weeks. |
Sorry, something went wrong.
|
I am fine with the PR. The primary concern in my implementation was to have mock_timeout fit in the API along with either to have a default or wait forever and hope we have reached some consensus on it as per the PR. It would be helpful if one of the core dev accepts this idea for merge. Also does it needs some more discussion from other channels like discourse, mailing list etc since I don't have experience in proposing new API. Thanks Mario for picking up the PR. |
Sorry, something went wrong.
What does it mean to have timeout namespaced? Have a parameter called "mock_timeout"? |
Sorry, something went wrong.
|
Yeah, just prepending it with “mock_”, mothibg fancy. having just ‘timeout’ can easily collide with existing functions that take a timeout parameter. |
Sorry, something went wrong.
|
Gentle ping @lisroach @voidspace, just wished yesterday that I had this mock in a codebase :). |
Sorry, something went wrong.
|
@mariocj89 - might be worth emailing or otherwise contacting @lisroach and @voidspace offline, I know GitHub notifications can be noisy for some people and a ping on here may not get to them. |
Sorry, something went wrong.
|
I don't think adding an additional class is justified enough. It does not really make Mock anymore "threaded" than it already is, just adds a convenience method on top of the threading facility. @cjw296 was already confused with the name above. Recall that unittest is somewhat hard to navigate already. I'm also not convinced that implementation is convenient enough: e.g. the implementation does not allow to wait for arbitrary conditions. One way or another let's get it through. |
Sorry, something went wrong.
|
Perhaps with the release of 3.9 it's time to consider this change for 3.10? |
Sorry, something went wrong.
|
I love the functionality of this, obviously it is solving some real-world problems. I think @Kentzo makes a good point, does it add enough functionality to justify creating a new class? Adding the capability to Mock on the backend is a nicer experience for end-users, who don't have to learn about the new class to get the same functionality. @Kentzo have the backwards compatibility issues with #20759 been resolved? I agree with Pablo that backwards compatibility is a must, even if we have to sacrifice some features. ThreadingMock fits with the Mock code-style and behavior, and the addition of a new class would not cause any breaking changes. |
Sorry, something went wrong.
|
@lisroach Yes, the issue that was pointed out (I changed the called property from a boolean to a boolean-alike object) was resolved: I added the call_event property instead. |
Sorry, something went wrong.
|
Just one plea here: many people are stuck on older versions of Python, and so only get to use new stuff via the backport, if at all possible, please have a thought to writing code in such a way that it'll run on Python 3.6. We already had to skip the "position-only args" commit in the backport, and that was pretty painful. |
Sorry, something went wrong.
I'm absolutely fine with that. A year ago there was a discussion where it seems that you and @voidspace where leaning more towards having specific mocks for different functionality, where it was discussed to have this implemented as such. But if things have changed I'm 100% fine with that :). Should we then close this PR go with @Kentzo proposal? |
Sorry, something went wrong.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️Hi! The buildbot wasm32-emscripten node (dynamic linking) 3.x has failed when building commit d65b783. What do you need to do:
You can take a look at the buildbot page here: https://buildbot.python.org/all/#builders/1056/builds/2437 Failed tests:
Failed subtests:
Summary of the results of the build (if available): == Tests result: FAILURE == 325 tests OK. 10 slowest tests:
1 test failed: 120 tests skipped: Total duration: 25 min 3 sec Click to see traceback logsTraceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 107, in test_wait_success_with_instance_timeout
self.run_async(something.method_1, delay=0.01)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 185, in test_wait_until_any_call_keywords
self.run_async(something.method_1, a=1, delay=0.1)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 157, in test_wait_magic_method
self.run_async(something.method_1.__str__, delay=0.01)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 117, in test_wait_failed_with_instance_timeout
self.run_async(something.method_1, delay=0.5)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 97, in test_wait_success
self.run_async(something.method_1, delay=0.01)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 231, in test_wait_until_any_call_change_global_and_override
self.run_async(m1, delay=0.1)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 128, in test_wait_success_with_timeout_override
self.run_async(something.method_1, delay=0.05)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 136, in test_wait_failed_with_timeout_override
self.run_async(something.method_1, delay=0.1)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 166, in test_wait_until_any_call_positional
self.run_async(something.method_1, 1, delay=0.1)
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-dl/build/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
|
Sorry, something went wrong.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️Hi! The buildbot wasm32-emscripten node (pthreads) 3.x has failed when building commit d65b783. What do you need to do:
You can take a look at the buildbot page here: https://buildbot.python.org/all/#builders/1050/builds/2426 Failed tests:
Failed subtests:
Summary of the results of the build (if available): == Tests result: FAILURE == 329 tests OK. 10 slowest tests:
1 test failed: 116 tests skipped: Total duration: 25 min 59 sec Click to see traceback logsTraceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-pthreads/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 188, in test_wait_until_any_call_keywords
self.assertNotIn(call(a=1), something.method_1.mock_calls)
AssertionError: call(a=1) unexpectedly found in [call(a=1)]
|
Sorry, something went wrong.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️Hi! The buildbot wasm32-wasi 3.x has failed when building commit d65b783. What do you need to do:
You can take a look at the buildbot page here: https://buildbot.python.org/all/#builders/1046/builds/2414 Failed tests:
Failed subtests:
Summary of the results of the build (if available): == Tests result: FAILURE == 317 tests OK. 10 slowest tests:
1 test failed: 128 tests skipped: Total duration: 6 min 19 sec Click to see traceback logsTraceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 107, in test_wait_success_with_instance_timeout
self.run_async(something.method_1, delay=0.01)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 185, in test_wait_until_any_call_keywords
self.run_async(something.method_1, a=1, delay=0.1)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 128, in test_wait_success_with_timeout_override
self.run_async(something.method_1, delay=0.05)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 231, in test_wait_until_any_call_change_global_and_override
self.run_async(m1, delay=0.1)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 117, in test_wait_failed_with_instance_timeout
self.run_async(something.method_1, delay=0.5)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 136, in test_wait_failed_with_timeout_override
self.run_async(something.method_1, delay=0.1)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 166, in test_wait_until_any_call_positional
self.run_async(something.method_1, 1, delay=0.1)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 157, in test_wait_magic_method
self.run_async(something.method_1.__str__, delay=0.01)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Traceback (most recent call last):
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 97, in test_wait_success
self.run_async(something.method_1, delay=0.01)
File "/Lib/test/test_unittest/testmock/testthreadingmock.py", line 28, in run_async
self._executor.submit(
File "/Lib/concurrent/futures/thread.py", line 179, in submit
self._adjust_thread_count()
File "/Lib/concurrent/futures/thread.py", line 202, in _adjust_thread_count
t.start()
File "/Lib/threading.py", line 971, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
|
Sorry, something went wrong.
|
OK! Let's see the results: 1. wasm32-emscripten node:RuntimeError: can't start new thread 2. wasm32-emscripten node (pthreads) 3.xFails with: ======================================================================
FAIL: test_wait_until_any_call_keywords (test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_until_any_call_keywords)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/buildbot/bcannon-wasm/3.x.bcannon-wasm.emscripten-node-pthreads/build/Lib/test/test_unittest/testmock/testthreadingmock.py", line 188, in test_wait_until_any_call_keywords
self.assertNotIn(call(a=1), something.method_1.mock_calls)
AssertionError: call(a=1) unexpectedly found in [call(a=1)]
3. wasm32-wasi 3.xRuntimeError: can't start new thread |
Sorry, something went wrong.
|
I'm worried 2 might come from flaky tests, will review them all to make sure we can make them more resilient (as you know, with timeouts we are exposed to the host). Need also to investigate what is going on with the error to start a thread. |
Sorry, something went wrong.
|
@mariocj89 Since the failures are in wasm related builds where threads might not be supported maybe you need to wrap the test file to skip when threads are not working. I see requires_working_threading being used in many tests. The docstring also notes threading related tests might fail in wasm builds. I guess wasm related builds are only during full test run and is not present in GitHub actions. cpython/Lib/test/support/threading_helper.py Lines 216 to 247 in 5890621 |
Sorry, something went wrong.
|
Indeed, just spoke with @pablogsal who told me the same :P. Will send a PR before EOD. |
Sorry, something went wrong.
|
It seems below tests are totally skipped and maybe a related one needs to be added to the mock related tests as well. Since the test will be backported to mock backport project maybe the helper function needs to be inlined in case mock backport runs on wasm builds to not rely on test.support rg '^threading_helper.requires_working_threading' Lib/test Lib/test/test_queue.py 14:threading_helper.requires_working_threading(module=True) Lib/test/test_thread.py 13:threading_helper.requires_working_threading(module=True) Lib/test/test_threading_local.py 15:threading_helper.requires_working_threading(module=True) Lib/test/test_threading.py 29:threading_helper.requires_working_threading(module=True) Lib/test/test_threadedtempfile.py 24:threading_helper.requires_working_threading(module=True) Lib/test/test_importlib/test_locks.py 15:threading_helper.requires_working_threading(module=True) Lib/test/test_importlib/test_threaded_import.py 22:threading_helper.requires_working_threading(module=True) |
Sorry, something went wrong.
|
PR to add the marker: #106366 Will followup trying to harden the rests of the tests. |
Sorry, something went wrong.
* main: (167 commits) pythongh-91053: make func watcher tests resilient to other func watchers (python#106286) pythongh-104050: Add more type hints to Argument Clinic DSLParser() (python#106354) pythongh-106359: Fix corner case bugs in Argument Clinic converter parser (python#106361) pythongh-104146: Remove unused attr 'parameter_indent' from clinic.DLParser (python#106358) pythongh-106320: Remove private _PyErr C API functions (python#106356) pythongh-104050: Annotate Argument Clinic DSLParser attributes (python#106357) pythongh-106320: Create pycore_modsupport.h header file (python#106355) pythongh-106320: Move _PyUnicodeWriter to the internal C API (python#106342) pythongh-61215: New mock to wait for multi-threaded events to happen (python#16094) Document PYTHONSAFEPATH along side -P (python#106122) Replace the esoteric term 'datum' when describing dict comprehensions (python#106119) pythongh-104050: Add more type hints to Argument Clinic DSLParser() (python#106343) pythongh-106320: _testcapi avoids private _PyUnicode_EqualToASCIIString() (python#106341) pythongh-106320: Add pycore_complexobject.h header file (python#106339) pythongh-106078: Move DecimalException to _decimal state (python#106301) pythongh-106320: Use _PyInterpreterState_GET() (python#106336) pythongh-106320: Remove private _PyInterpreterState functions (python#106335) pythongh-104922: Doc: add note about PY_SSIZE_T_CLEAN (python#106314) pythongh-106217: Truncate the issue body size of `new-bugs-announce-notifier` (python#106329) pythongh-104922: remove PY_SSIZE_T_CLEAN (python#106315) ...
|
@cjw296 even though the API looks neat to me, I showed it to a colleague who does not have a lot of mocking experiencet and suggested to use wait_for_called_with rather than wait_for_any_call. Whilst I like how wait_for_any_call mirrors the naming convention with assert_any_call and leaves the door open to use wait_for_called_with to fail if the next call does not match the specified call, it might be easier to read to just call it wait_for_called_with and if we ever need a "wait for called with X and fail if different" we could name it "wait_for_next_call". What do you think? mock = ThreadingMock()
mock.wait_for_any_call("arg1", kwarg2=2) #1
mock.wait_for_call_with("arg1", kwarg2=2) #2
1 or 2? I'm fine with one, but if we want to change it, it is possibly now or never. |
Sorry, something went wrong.
|
Maybe it should be wait_for_any_call_with? |
Sorry, something went wrong.
|
Sounds good. PR ready: #106414 |
Sorry, something went wrong.
|
There seems to be another problem with this -- I just got a test flake, apparently due to the use of short fixed timeouts in the test added here. See https://github.com/python/cpython/actions/runs/5559403783/jobs/10155484726. |
Sorry, something went wrong.
|
Not sure what a "test flake" means in this context? Looking at the test again, I'm unclear it's sensible: cpython/Lib/test/test_unittest/testmock/testthreadingmock.py Lines 166 to 180 in 0db85ee Why the delays of 0.2, 0.5 and 0.6? Lines 178-180 suppose that because call(3) has occurred, then call(2) will have occurred. Again, that seems likely given the 0.1s delay but not guaranteed, and indeed seems to have not happened here. What could lead these to be out of order? Some funny OS-level scheduler thing on that macOS runner? Something on @gvanrossum's branch? FWIW, this is the first time I'm aware of this test failing, and it's run nightly on a bunch of different python versions in the backport CI: https://app.circleci.com/pipelines/github/testing-cabal/mock?branch=master @mariocj89 - what are your thoughts on this? What can we do to make this test reliable. A bonus would be to make them faster to run, these threading tests are noticeably much slower than the other mock tests... |
Sorry, something went wrong.
|
It is a hard balance to keep the tests fast but reliable. I will try changing this to have short retrying timeouts to make that happen. Will send a PR on Monday if there is not rush as I don't have access to a PC this weekend |
Sorry, something went wrong.
A flaky test is a test that usually passes but sometimes fails. Tests that rely on timeouts are often flaky (but there are other causes). Any large complex system has flaky tests. In this case, the test failed in CI on macOS only; Windows and Ubuntu were fine. Re-running the test on my machine locally it passes. That makes it flaky in my book. Note that, as defense against flaky tests, our CI machinery re-runs a failed test once and if it passes the second time, it is accepted. In this case we were apparently unlucky with the timeouts twice in a row. Thanks for having a second look at these tests! |
Sorry, something went wrong.
|
#106822 should prevent any future failure. |
Sorry, something went wrong.
|
Is this change going to be included in 3.12? |
Sorry, something went wrong.
|
I haven’t checked the source but I see no evidence of a backport to the 3.12 branch, so presumably not. |
Sorry, something went wrong.
|
@Kentzo - it doesn't look like ThreadingMock made it into https://github.com/python/cpython/blob/3.12/Lib/unittest/mock.py, so no need for this fix. ThreadingMock is available in the the mock rolling backport if you want to use it before 3.13 is out: |
Sorry, something went wrong.
|
Is it possible to use ThreadingMock with auto spec feature? i.e. let patch or create_autospec create a ThreadingMock instance instead of a MagicMock instance. |
Sorry, something went wrong.
|
Per the mocks docs: You can specify an alternative class of Mock using the new_callable argument to patch(). That should work in theory, give it a try! |
Sorry, something went wrong.
This is not possible with autospec. The #1 reason for using patch :-(. ValueError: Cannot use 'autospec' and 'new_callable' together |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR implements the change proposed in bpo-17013 and takes over #12818 (agreed offline with @tirkarthi).
https://bugs.python.org/issue17013
CC: @tirkarthi @voidspace @lisroach