0

Is there any way to disconect models signals in test mode Django 1.11 ?

Or maybe a way to create an object without ORM to prevent dispaching signal from the post_save method ?

setup test code

def setUp(self):
   #some code
   with patch(post_save):
       self.instance = Instance.objects.create(fields)

error : AttributeError: 'ModelSignal' object has no attribute 'rsplit'

Beliaf
  • 577
  • 2
  • 8
  • 25

1 Answers1

1

These signals shouldn't really be mocked, but if you really need to do it, this should work:

from unittest.mock import patch

def test_method(self):
    with patch('django.db.models.signals.post_save.send'):
        MyObject.objects.create()
arikan
  • 893
  • 9
  • 18