← Back to team overview

maas-devel team mailing list archive

Be careful when you use Mock patching in tests

 

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.


Follow ups