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

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -