From 5e60a97b0f9fff946746a460b26c9305207e6f3c Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Thu, 10 Sep 2020 16:32:52 +0200 Subject: [PATCH] test: fix flaky sequencer unit tests Patching the client under test should be done on an instance used in a test, not on the instance's class - patching the latter can cause all other instances of the same class to share the patched method, possibly interfering with the patched method's call count. --- tests/unit/pubsub_v1/publisher/test_publisher_client.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/unit/pubsub_v1/publisher/test_publisher_client.py b/tests/unit/pubsub_v1/publisher/test_publisher_client.py index bcdbb2f34..1760482ac 100644 --- a/tests/unit/pubsub_v1/publisher/test_publisher_client.py +++ b/tests/unit/pubsub_v1/publisher/test_publisher_client.py @@ -435,9 +435,7 @@ def test_wait_and_commit_sequencers(): # Mock out time so no sleep is actually done. with mock.patch.object(time, "sleep"): - with mock.patch.object( - publisher.Client, "_commit_sequencers" - ) as _commit_sequencers: + with mock.patch.object(client, "_commit_sequencers") as _commit_sequencers: assert ( client.publish("topic", b"bytestring body", ordering_key="") is not None ) @@ -456,9 +454,7 @@ def test_stopped_client_does_not_commit_sequencers(): # Mock out time so no sleep is actually done. with mock.patch.object(time, "sleep"): - with mock.patch.object( - publisher.Client, "_commit_sequencers" - ) as _commit_sequencers: + with mock.patch.object(client, "_commit_sequencers") as _commit_sequencers: assert ( client.publish("topic", b"bytestring body", ordering_key="") is not None )