django - How to disable/disconnect m2m_changed signal during testing? -


i trying load fixture during django test case, m2m_changed signal kicks in , gives error (the signal checks foreignkey in related state).

this answer suggests using disable_for_loaddata decorator, m2m_changed doesn't have raw field.

i have tried:

class daystests(apitestcase):     fixtures = ['initial_data.json'] # fixture loaded before disabling m2m_changed     def setup(self):         m2m_changed.disconnect(days_handler, sender=foo.days.through)      def test_api(self):         # test logic. 

initial data loaded before disabling m2m_changed signal.

what right way disconnect/disable m2m_changed signal?

you should try disable signal not in setup method in setupclass because it's executed before loading fixtures. possible way use it:

@classmethod def setupclass(cls):     super(daystests, cls).setupclass()     m2m_changed.disconnect(...) 

Comments

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -