def test_incall(self): self.tracer.watch('testmod.a') with self.tm: self.assertFalse(self.tracer.incall) def test(): self.assertTrue(self.tracer.incall) with mock.patch('testmod.b', test): testmod.a()
def test_child_tracer(self): t = mock.Mock() self.tracer.watch('testmod.a') child = tracerlib.Tracer(t, ['call'], ['testmod.b'], parent=self.tracer) self.tm.add(child) self.assertEqual(0, t.call_count, 'Tracer called before even enabling!') with self.tm: self.assertEqual(0, t.call_count, 'Tracer called before calling function!') testmod.b() self.assertEqual(0, t.call_count, 'Tracer called when parent was not in-call!') with self.tm: testmod.a() self.assertEqual(1, t.call_count)