From 962997ed160eefdb309d73add39ffb3d9431f560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastien=20G=C3=A9rard?= Date: Sun, 26 May 2019 22:33:04 +0200 Subject: [PATCH] fix flaky test due to signal receiver garbage collection --- tests/document/instance.py | 4 ++++ tests/test_signals.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/tests/document/instance.py b/tests/document/instance.py index 5d4cd1da..f4527ad8 100644 --- a/tests/document/instance.py +++ b/tests/document/instance.py @@ -751,6 +751,10 @@ class InstanceTest(MongoDBTestCase): '_id': post.id }) + # Important to disconnect as it could cause some assertions in test_signals + # to fail (due to the garbage collection timing of this signal) + signals.pre_save_post_validation.disconnect(BlogPost.pre_save_post_validation) + def test_document_clean(self): class TestDocument(Document): status = StringField() diff --git a/tests/test_signals.py b/tests/test_signals.py index f3b6e33c..34cb43c3 100644 --- a/tests/test_signals.py +++ b/tests/test_signals.py @@ -227,6 +227,9 @@ class SignalTests(unittest.TestCase): self.ExplicitId.objects.delete() + # Note that there is a chance that the following assert fails in case + # some receivers (eventually created in other tests) + # gets garbage collected (https://pythonhosted.org/blinker/#blinker.base.Signal.connect) self.assertEqual(self.pre_signals, post_signals) def test_model_signals(self):