fix flaky test due to signal receiver garbage collection

This commit is contained in:
Bastien Gérard 2019-05-26 22:33:04 +02:00
parent daca0ebc14
commit 962997ed16
2 changed files with 7 additions and 0 deletions

View File

@ -751,6 +751,10 @@ class InstanceTest(MongoDBTestCase):
'_id': post.id '_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): def test_document_clean(self):
class TestDocument(Document): class TestDocument(Document):
status = StringField() status = StringField()

View File

@ -227,6 +227,9 @@ class SignalTests(unittest.TestCase):
self.ExplicitId.objects.delete() 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) self.assertEqual(self.pre_signals, post_signals)
def test_model_signals(self): def test_model_signals(self):