concurrent question

15 views
Skip to first unread message

Alex Arshavski

unread,
Feb 3, 2022, 1:45:45 PM2/3/22
to pywe...@googlegroups.com
Hi,

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():
pass
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

unread,
Feb 3, 2022, 1:51:05 PM2/3/22
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 pyweb-il+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyweb-il/CABJrdTJLDp3CNHjcbjGgyXDzGS8ufQuspxX%2BPpK%2BvTU4ou_JqQ%40mail.gmail.com.

Ram Rachum

unread,
Feb 3, 2022, 1:51:34 PM2/3/22
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

unread,
Feb 3, 2022, 3:25:22 PM2/3/22
to pywe...@googlegroups.com
def f(callback=None):
    ...
    while ...:
       callback and callback()
    ...

Reply all
Reply to author
Forward
0 new messages