concurrent question

Skip to first unread message

Alex Arshavski

Feb 3, 2022, 1:45:45 PMFeb 3

I have some testing question:
I have the following code:
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(send_slack_message, param1, param2, param3)
while future.running():
logging.warning("Slack message sent")
My question is

How can I write a test which checks that I get inside the "while" ?
I use unittest with @patch.
I mean, what should be mocked here and how?

Thanks, Alex A.

Ram Rachum

Feb 3, 2022, 1:51:05 PMFeb 3
to pyweb-il
I think you asked your question in a way that's so detached from what you're trying to achieve, that I don't know how to help you. 

If I did answer your question directly, I would probably say to add a function inside the `while`, which would be no-op by default but the test could insert a different function instead of it that it listens to. Or put a log there that the test listens to. But you already knew that, so you're probably looking for something else. 

You received this message because you are subscribed to the Google Groups "PyWeb-IL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Ram Rachum

Feb 3, 2022, 1:51:34 PMFeb 3
to pyweb-il
Also, the example is so detached from how `futures` is used, and that makes it harder to understand what's going on. 

Aur Saraf

Feb 3, 2022, 3:25:22 PMFeb 3
def f(callback=None):
    while ...:
       callback and callback()

Reply all
Reply to author
0 new messages