[Maas-devel] Be careful when you use Mock patching in tests

Julian Edwards julian.edwards at canonical.com
Tue Nov 5 06:55:50 UTC 2013


I just had to make this change because amazingly it had two innocuous bugs:

-------
  def test_write_full_dns_doesnt_call_task_it_no_interface_configured(self):
         self.patch(settings, 'DNS_CONNECT', True)
-        patched_task = self.patch(tasks, 'write_full_dns_config')
+        patched_task = self.patch(dns.tasks.write_full_dns_config, "delay")
         dns.write_full_dns_config()
         self.assertEqual(0, patched_task.call_count)
-------

Bug #1: Was naively patching the global "tasks" when it should be
patching the one that the dns module imported.

Bug #2: When patching out celery jobs, you need to patch the delay() call.




More information about the Maas-devel mailing list