Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-106458: Mark testthreadingmock.py with @requires_working_threading #106366

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions Lib/test/test_unittest/testmock/testthreadingmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
import unittest
import concurrent.futures

from test.support import threading_helper
from unittest.mock import patch, ThreadingMock, call


threading_helper.requires_working_threading(module=True)


class Something:
def method_1(self):
pass
Expand Down Expand Up @@ -133,11 +137,9 @@ def test_wait_failed_with_timeout_override(self):

with patch(f"{__name__}.Something", waitable_mock):
something = Something()
self.run_async(something.method_1, delay=0.1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariocj89 - this change and the ones below confuse me, are they intentional or just a result of a bad attempt of mine to resolve the conflicts?

Copy link
Contributor Author

@mariocj89 mariocj89 Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed part of the change. Trying to reduce the chance of a race condition (as that's what this test is doing though)

self.run_async(something.method_1, delay=0.5)
with self.assertRaises(AssertionError):
something.method_1.wait_until_called(timeout=0.05)
with self.assertRaises(AssertionError):
something.method_1.wait_until_any_call_with(timeout=0.05)

def test_wait_success_called_before(self):
waitable_mock = self._make_mock()
Expand All @@ -163,10 +165,10 @@ def test_wait_until_any_call_with_positional(self):

with patch(f"{__name__}.Something", waitable_mock):
something = Something()
self.run_async(something.method_1, 1, delay=0.1)
self.run_async(something.method_1, 2, delay=0.2)
self.run_async(something.method_1, 3, delay=0.3)
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)
Expand All @@ -182,10 +184,10 @@ def test_wait_until_any_call_with_keywords(self):

with patch(f"{__name__}.Something", waitable_mock):
something = Something()
self.run_async(something.method_1, a=1, delay=0.1)
self.run_async(something.method_1, b=2, delay=0.2)
self.run_async(something.method_1, c=3, delay=0.3)
self.run_async(something.method_1, a=1, delay=0.2)
self.assertNotIn(call(a=1), something.method_1.mock_calls)
self.run_async(something.method_1, b=2, delay=0.5)
self.run_async(something.method_1, c=3, delay=0.6)

something.method_1.wait_until_any_call_with(a=1)
something.method_1.assert_called_with(a=1)
Expand Down