GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-61215: New mock to wait for multi-threaded events to happen by mariocj89 · Pull Request #16094 · python/cpython

Conversation

@mariocj89

@mariocj89 mariocj89 commented Sep 13, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • Issue: Allow waiting on a mock #61215

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Sep 13, 2019
@bedevere-bot bedevere-bot added the awaiting review label Sep 13, 2019
@pablogsal
pablogsal requested review from lisroach and voidspace September 13, 2019 15:55
@mariocj89

mariocj89 commented Sep 13, 2019

Copy link
Copy Markdown
Contributor Author

Support for multiprocessing? If not, maybe rename to MultithreadingMock?

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.

tirkarthi reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89
mariocj89 marked this pull request as ready for review September 13, 2019 16:59
tirkarthi
tirkarthi reviewed Sep 13, 2019
View reviewed changes
Comment thread Lib/unittest/mock.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/unittest/mock.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/unittest/mock.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

mariocj89
mariocj89 commented Sep 14, 2019
View reviewed changes
Comment thread Lib/unittest/test/testmock/testthreadingmock.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Sep 29, 2019

Copy link
Copy Markdown
Contributor Author

Gentle ping @tirkarthi @voidspace @lisroach! Let me know if the general idea/naming looks good and I'll get to work on the documentation.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tirkarthi

tirkarthi commented Oct 1, 2019

Copy link
Copy Markdown
Member

Sorry, got caught up with new job. I will try to get to the PR after two weeks.

mariocj89 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tirkarthi tirkarthi mentioned this pull request Oct 19, 2019
[WIP] bpo-17013: Implement WaitableMock to create Mock objects that can wait until called #12818
Closed
@tirkarthi

tirkarthi commented Oct 19, 2019

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89
mariocj89 force-pushed the pu/eventmock branch 2 times, most recently from 317eb79 to 54c4a32 Compare October 21, 2019 09:23
vstinner
vstinner reviewed Oct 21, 2019
View reviewed changes
Comment thread Doc/library/unittest.mock.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 22, 2019

Copy link
Copy Markdown
Member

As a note, IIRC when speaking with @voidspace, he liked the idea of having the timeout namespaced. He can further comment.

What does it mean to have timeout namespaced? Have a parameter called "mock_timeout"?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Oct 22, 2019

Copy link
Copy Markdown
Contributor Author

Yeah, just prepending it with “mock_”, mothibg fancy.

having just ‘timeout’ can easily collide with existing functions that take a timeout parameter.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Kentzo
Kentzo reviewed Nov 12, 2019
View reviewed changes
Comment thread Lib/unittest/test/testmock/testthreadingmock.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Kentzo Kentzo mentioned this pull request Nov 12, 2019
bpo-17013: Extend Mock.called to allow waiting for calls #17133
Closed
@mariocj89

mariocj89 commented Dec 14, 2019

Copy link
Copy Markdown
Contributor Author

Gentle ping @lisroach @voidspace, just wished yesterday that I had this mock in a codebase :).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjw296

cjw296 commented Jan 24, 2020

Copy link
Copy Markdown
Contributor

@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.

mariocj89 and lisroach reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjw296
cjw296 reviewed Jan 26, 2020
View reviewed changes
Comment thread Doc/library/unittest.mock.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Kentzo

Kentzo commented Apr 27, 2020

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Kentzo Kentzo mentioned this pull request Jun 9, 2020
gh-61215: Add Mock.call_event to allow waiting for calls #20759
Closed
@Kentzo

Kentzo commented Oct 21, 2020

Copy link
Copy Markdown
Contributor

Perhaps with the release of 3.9 it's time to consider this change for 3.10?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89
mariocj89 force-pushed the pu/eventmock branch from b0383ae to 681abde Compare October 21, 2020 16:10
@lisroach

lisroach commented Oct 21, 2020

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Kentzo

Kentzo commented Oct 21, 2020

Copy link
Copy Markdown
Contributor

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjw296

cjw296 commented Oct 22, 2020

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Oct 22, 2020

Copy link
Copy Markdown
Contributor Author

I think @Kentzo makes a good point, does it add enough functionality to justify creating a new class

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Jul 3, 2023
@bedevere-bot

bedevere-bot commented Jul 3, 2023

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot wasm32-emscripten node (dynamic linking) 3.x has failed when building commit d65b783.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1056/builds/2437) and take a look at the build logs.
  4. Check if the failure is related to this commit (d65b783) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1056/builds/2437

Failed tests:

  • test_unittest

Failed subtests:

  • test_wait_magic_method - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_magic_method
  • test_wait_success_with_instance_timeout - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_success_with_instance_timeout
  • test_wait_success - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_success
  • test_wait_until_any_call_change_global_and_override - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_until_any_call_change_global_and_override
  • test_wait_success_with_timeout_override - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_success_with_timeout_override
  • test_wait_failed_with_instance_timeout - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_failed_with_instance_timeout
  • test_wait_until_any_call_keywords - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_until_any_call_keywords
  • test_wait_until_any_call_positional - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_until_any_call_positional
  • test_wait_failed_with_timeout_override - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_failed_with_timeout_override

Summary of the results of the build (if available):

== Tests result: FAILURE ==

325 tests OK.

10 slowest tests:

  • test_math: 1 min 44 sec
  • test_hashlib: 1 min 41 sec
  • test_unparse: 49.0 sec
  • test_tokenize: 43.6 sec
  • test_capi: 29.1 sec
  • test_fstring: 28.5 sec
  • test_tarfile: 27.2 sec
  • test_unicodedata: 25.7 sec
  • test_zipfile: 18.5 sec
  • test_pickle: 18.2 sec

1 test failed:
test_unittest

120 tests skipped:
test.test_asyncio.test_base_events
test.test_asyncio.test_buffered_proto
test.test_asyncio.test_context
test.test_asyncio.test_eager_task_factory
test.test_asyncio.test_events test.test_asyncio.test_futures
test.test_asyncio.test_futures2 test.test_asyncio.test_locks
test.test_asyncio.test_pep492
test.test_asyncio.test_proactor_events
test.test_asyncio.test_protocols test.test_asyncio.test_queues
test.test_asyncio.test_runners
test.test_asyncio.test_selector_events
test.test_asyncio.test_sendfile test.test_asyncio.test_server
test.test_asyncio.test_sock_lowlevel test.test_asyncio.test_ssl
test.test_asyncio.test_sslproto test.test_asyncio.test_streams
test.test_asyncio.test_subprocess
test.test_asyncio.test_taskgroups test.test_asyncio.test_tasks
test.test_asyncio.test_threads test.test_asyncio.test_timeouts
test.test_asyncio.test_transports
test.test_asyncio.test_unix_events test.test_asyncio.test_waitfor
test.test_asyncio.test_windows_events
test.test_asyncio.test_windows_utils test__xxinterpchannels
test__xxsubinterpreters test_asyncgen test_clinic test_cmd_line
test_concurrent_futures test_contextlib_async test_ctypes
test_curses test_dbm_gnu test_dbm_ndbm test_devpoll test_doctest
test_docxmlrpc test_dtrace test_embed test_epoll test_faulthandler
test_fcntl test_file_eintr test_fork1 test_ftplib test_gdb
test_grp test_httplib test_httpservers test_idle test_imaplib
test_interpreters test_ioctl test_kqueue test_launcher test_lzma
test_mmap test_multiprocessing_fork
test_multiprocessing_forkserver test_multiprocessing_main_handling
test_multiprocessing_spawn test_openpty test_pdb
test_perf_profiler test_perfmaps test_poll test_poplib test_pty
test_pwd test_queue test_readline test_regrtest test_repl
test_resource test_select test_selectors test_smtplib test_smtpnet
test_socket test_socketserver test_ssl test_stable_abi_ctypes
test_startfile test_subprocess test_sys_settrace test_syslog
test_tcl test_thread test_threadedtempfile test_threading
test_threading_local test_tkinter test_tools test_ttk
test_ttk_textonly test_turtle test_urllib2 test_urllib2_localnet
test_urllib2net test_urllibnet test_venv test_wait3 test_wait4
test_webbrowser test_winconsoleio test_winreg test_winsound
test_wmi test_wsgiref test_xmlrpc test_zipfile64
test_zipimport_support test_zoneinfo
0:25:03 load avg: 11.72
0:25:03 load avg: 11.72 Re-running failed tests is not supported with --python host runner option.

Total duration: 25 min 3 sec

Click to see traceback logs
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 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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Jul 3, 2023

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot wasm32-emscripten node (pthreads) 3.x has failed when building commit d65b783.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1050/builds/2426) and take a look at the build logs.
  4. Check if the failure is related to this commit (d65b783) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1050/builds/2426

Failed tests:

  • test_unittest

Failed subtests:

  • test_wait_until_any_call_keywords - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_until_any_call_keywords

Summary of the results of the build (if available):

== Tests result: FAILURE ==

329 tests OK.

10 slowest tests:

  • test_hashlib: 2 min 16 sec
  • test_math: 2 min 5 sec
  • test_tarfile: 1 min 14 sec
  • test_tokenize: 43.7 sec
  • test_unparse: 43.1 sec
  • test_io: 37.7 sec
  • test_capi: 37.0 sec
  • test_unicodedata: 29.5 sec
  • test_pathlib: 27.8 sec
  • test_pickle: 23.2 sec

1 test failed:
test_unittest

116 tests skipped:
test.test_asyncio.test_base_events
test.test_asyncio.test_buffered_proto
test.test_asyncio.test_context
test.test_asyncio.test_eager_task_factory
test.test_asyncio.test_events test.test_asyncio.test_futures
test.test_asyncio.test_futures2 test.test_asyncio.test_locks
test.test_asyncio.test_pep492
test.test_asyncio.test_proactor_events
test.test_asyncio.test_protocols test.test_asyncio.test_queues
test.test_asyncio.test_runners
test.test_asyncio.test_selector_events
test.test_asyncio.test_sendfile test.test_asyncio.test_server
test.test_asyncio.test_sock_lowlevel test.test_asyncio.test_ssl
test.test_asyncio.test_sslproto test.test_asyncio.test_streams
test.test_asyncio.test_subprocess
test.test_asyncio.test_taskgroups test.test_asyncio.test_tasks
test.test_asyncio.test_threads test.test_asyncio.test_timeouts
test.test_asyncio.test_transports
test.test_asyncio.test_unix_events test.test_asyncio.test_waitfor
test.test_asyncio.test_windows_events
test.test_asyncio.test_windows_utils test__xxinterpchannels
test__xxsubinterpreters test_asyncgen test_clinic test_cmd_line
test_concurrent_futures test_contextlib_async test_ctypes
test_curses test_dbm_gnu test_dbm_ndbm test_devpoll test_doctest
test_docxmlrpc test_dtrace test_embed test_epoll test_faulthandler
test_fcntl test_file_eintr test_fork1 test_ftplib test_gdb
test_grp test_httplib test_httpservers test_idle test_imaplib
test_interpreters test_ioctl test_kqueue test_launcher test_lzma
test_mmap test_multiprocessing_fork
test_multiprocessing_forkserver test_multiprocessing_main_handling
test_multiprocessing_spawn test_openpty test_pdb
test_perf_profiler test_perfmaps test_poll test_poplib test_pty
test_pwd test_readline test_regrtest test_repl test_resource
test_select test_selectors test_smtplib test_smtpnet test_socket
test_socketserver test_ssl test_stable_abi_ctypes test_startfile
test_subprocess test_sys_settrace test_syslog test_tcl
test_tkinter test_tools test_ttk test_ttk_textonly test_turtle
test_urllib2 test_urllib2_localnet test_urllib2net test_urllibnet
test_venv test_wait3 test_wait4 test_webbrowser test_winconsoleio
test_winreg test_winsound test_wmi test_wsgiref test_xmlrpc
test_xxlimited test_zipfile64 test_zipimport_support test_zoneinfo
0:25:59 load avg: 7.86
0:25:59 load avg: 7.86 Re-running failed tests is not supported with --python host runner option.

Total duration: 25 min 59 sec

Click to see traceback logs
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)]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Jul 3, 2023

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot wasm32-wasi 3.x has failed when building commit d65b783.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1046/builds/2414) and take a look at the build logs.
  4. Check if the failure is related to this commit (d65b783) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1046/builds/2414

Failed tests:

  • test_unittest

Failed subtests:

  • test_wait_magic_method - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_magic_method
  • test_wait_success_with_instance_timeout - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_success_with_instance_timeout
  • test_wait_success - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_success
  • test_wait_until_any_call_change_global_and_override - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_until_any_call_change_global_and_override
  • test_wait_success_with_timeout_override - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_success_with_timeout_override
  • test_wait_failed_with_instance_timeout - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_failed_with_instance_timeout
  • test_wait_until_any_call_keywords - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_until_any_call_keywords
  • test_wait_until_any_call_positional - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_until_any_call_positional
  • test_wait_failed_with_timeout_override - test.test_unittest.testmock.testthreadingmock.TestThreadingMock.test_wait_failed_with_timeout_override

Summary of the results of the build (if available):

== Tests result: FAILURE ==

317 tests OK.

10 slowest tests:

  • test_hashlib: 1 min 12 sec
  • test_math: 1 min 11 sec
  • test_tokenize: 42.9 sec
  • test_capi: 32.1 sec
  • test_unparse: 30.2 sec
  • test_unicodedata: 25.1 sec
  • test_pickle: 22.6 sec
  • test_tarfile: 19.1 sec
  • test_decimal: 12.7 sec
  • test_fstring: 11.8 sec

1 test failed:
test_unittest

128 tests skipped:
test.test_asyncio.test_base_events
test.test_asyncio.test_buffered_proto
test.test_asyncio.test_context
test.test_asyncio.test_eager_task_factory
test.test_asyncio.test_events test.test_asyncio.test_futures
test.test_asyncio.test_futures2 test.test_asyncio.test_locks
test.test_asyncio.test_pep492
test.test_asyncio.test_proactor_events
test.test_asyncio.test_protocols test.test_asyncio.test_queues
test.test_asyncio.test_runners
test.test_asyncio.test_selector_events
test.test_asyncio.test_sendfile test.test_asyncio.test_server
test.test_asyncio.test_sock_lowlevel test.test_asyncio.test_ssl
test.test_asyncio.test_sslproto test.test_asyncio.test_streams
test.test_asyncio.test_subprocess
test.test_asyncio.test_taskgroups test.test_asyncio.test_tasks
test.test_asyncio.test_threads test.test_asyncio.test_timeouts
test.test_asyncio.test_transports
test.test_asyncio.test_unix_events test.test_asyncio.test_waitfor
test.test_asyncio.test_windows_events
test.test_asyncio.test_windows_utils test__xxinterpchannels
test__xxsubinterpreters test_asyncgen test_bz2 test_clinic
test_cmd_line test_concurrent_futures test_contextlib_async
test_ctypes test_curses test_dbm_gnu test_dbm_ndbm test_devpoll
test_doctest test_docxmlrpc test_dtrace test_embed test_epoll
test_faulthandler test_fcntl test_file_eintr test_fork1
test_ftplib test_gdb test_grp test_gzip test_httplib
test_httpservers test_idle test_imaplib test_interpreters
test_ioctl test_kqueue test_launcher test_lzma test_mailbox
test_mmap test_multiprocessing_fork
test_multiprocessing_forkserver test_multiprocessing_main_handling
test_multiprocessing_spawn test_openpty test_pdb
test_perf_profiler test_perfmaps test_poll test_poplib test_pty
test_pwd test_queue test_readline test_regrtest test_repl
test_resource test_select test_selectors test_smtplib test_smtpnet
test_socket test_socketserver test_sqlite3 test_ssl
test_stable_abi_ctypes test_startfile test_subprocess
test_sys_settrace test_syslog test_tcl test_thread
test_threadedtempfile test_threading test_threading_local
test_tkinter test_tools test_ttk test_ttk_textonly test_turtle
test_urllib test_urllib2 test_urllib2_localnet test_urllib2net
test_urllib_response test_urllibnet test_venv test_wait3
test_wait4 test_webbrowser test_winconsoleio test_winreg
test_winsound test_wmi test_wsgiref test_xmlrpc test_xxlimited
test_zipfile64 test_zipimport_support test_zlib test_zoneinfo
0:06:19 load avg: 2.14
0:06:19 load avg: 2.14 Re-running failed tests is not supported with --python host runner option.

Total duration: 6 min 19 sec

Click to see traceback logs
Traceback (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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89
mariocj89 deleted the pu/eventmock branch July 3, 2023 13:47
@mariocj89

mariocj89 commented Jul 3, 2023

Copy link
Copy Markdown
Contributor Author

OK! Let's see the results:

1. wasm32-emscripten node:

RuntimeError: can't start new thread

2. wasm32-emscripten node (pthreads) 3.x

Fails 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.x

RuntimeError: can't start new thread

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Jul 3, 2023

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tirkarthi

tirkarthi commented Jul 3, 2023

Copy link
Copy Markdown
Member

@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

def _can_start_thread() -> bool:
"""Detect whether Python can start new threads.
Some WebAssembly platforms do not provide a working pthread
implementation. Thread support is stubbed and any attempt
to create a new thread fails.
- wasm32-wasi does not have threading.
- wasm32-emscripten can be compiled with or without pthread
support (-s USE_PTHREADS / __EMSCRIPTEN_PTHREADS__).
"""
if sys.platform == "emscripten":
return sys._emscripten_info.pthreads
elif sys.platform == "wasi":
return False
else:
# assume all other platforms have working thread support.
return True
can_start_thread = _can_start_thread()
def requires_working_threading(*, module=False):
"""Skip tests or modules that require working threading.
Can be used as a function/class decorator or to skip an entire module.
"""
msg = "requires threading support"
if module:
if not can_start_thread:
raise unittest.SkipTest(msg)
else:
return unittest.skipUnless(can_start_thread, msg)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Jul 3, 2023

Copy link
Copy Markdown
Contributor Author

Indeed, just spoke with @pablogsal who told me the same :P.

Will send a PR before EOD.

tirkarthi and cjw296 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tirkarthi

tirkarthi commented Jul 3, 2023

Copy link
Copy Markdown
Member

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)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Jul 3, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

PR to add the marker: #106366

Will followup trying to harden the rests of the tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

carljm added a commit to carljm/cpython that referenced this pull request Jul 3, 2023
@carljm
Merge branch 'main' into modulelocals
ac11740
* 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)
  ...
@mariocj89

mariocj89 commented Jul 3, 2023

Copy link
Copy Markdown
Contributor Author

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjw296

cjw296 commented Jul 4, 2023

Copy link
Copy Markdown
Contributor

Maybe it should be wait_for_any_call_with?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Jul 4, 2023

Copy link
Copy Markdown
Contributor Author

Sounds good. PR ready: #106414

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89 mariocj89 mentioned this pull request Jul 4, 2023
gh-61215: Rename wait_until_any_call to wait_until_any_call_with #106414
Merged
@brettcannon brettcannon mentioned this pull request Jul 5, 2023
test_unittest failing due to test/test_unittest/testmock/testthreadingmock assuming threading exists #106458
Closed
cjw296
cjw296 reviewed Jul 10, 2023
View reviewed changes
Comment thread Lib/unittest/mock.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

cjw296
cjw296 reviewed Jul 10, 2023
View reviewed changes
Comment thread Lib/test/test_unittest/testmock/testthreadingmock.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented Jul 15, 2023

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjw296

cjw296 commented Jul 15, 2023

Copy link
Copy Markdown
Contributor

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

with patch(f"{__name__}.Something", waitable_mock):
something = Something()
self.run_async(something.method_1, 1, delay=0.2)
self.assertNotIn(call(1), something.method_1.mock_calls)
self.run_async(something.method_1, 2, delay=0.5)
self.run_async(something.method_1, 3, delay=0.6)
something.method_1.wait_until_any_call_with(1)
something.method_1.assert_called_with(1)
self.assertNotIn(call(2), something.method_1.mock_calls)
self.assertNotIn(call(3), something.method_1.mock_calls)
something.method_1.wait_until_any_call_with(3)
self.assertIn(call(2), something.method_1.mock_calls)
something.method_1.wait_until_any_call_with(2)

Why the delays of 0.2, 0.5 and 0.6?
The assertions on lines 169, 175 and 176 seem likely but not guaranteed?

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
Those are all on Linux, mind...

@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...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Jul 15, 2023

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented Jul 15, 2023

Copy link
Copy Markdown
Member

Not sure what a "test flake" means in this context?

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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Jul 17, 2023

Copy link
Copy Markdown
Contributor Author

#106822 should prevent any future failure.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Kentzo

Kentzo commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

Is this change going to be included in 3.12?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented Aug 30, 2023

Copy link
Copy Markdown
Member

I haven’t checked the source but I see no evidence of a backport to the 3.12 branch, so presumably not.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjw296

cjw296 commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

@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:
https://mock.readthedocs.io/en/latest/changelog.html#id1
https://pypi.org/project/mock/5.1.0/

Kentzo reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@owillebo

owillebo commented Sep 25, 2023

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mariocj89

mariocj89 commented Sep 25, 2023

Copy link
Copy Markdown
Contributor Author

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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@owillebo

owillebo commented Nov 15, 2023

Copy link
Copy Markdown

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!

This is not possible with autospec. The #1 reason for using patch :-(.

ValueError: Cannot use 'autospec' and 'new_callable' together

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@vstinner vstinner vstinner left review comments
@cjw296 cjw296 cjw296 approved these changes
@tirkarthi tirkarthi tirkarthi left review comments
@lisroach lisroach Awaiting requested review from lisroach
@voidspace voidspace Awaiting requested review from voidspace
@Kentzo Kentzo Awaiting requested review from Kentzo
+1 more reviewer
@owillebo owillebo owillebo left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

11 participants

@mariocj89 @tirkarthi @vstinner @cjw296 @Kentzo @lisroach @owillebo @bedevere-bot @gvanrossum @the-knights-who-say-ni @ezio-melotti
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.