(self)
| 306 | self.assertTrue(tracemalloc.is_tracing()) |
| 307 | |
| 308 | def test_snapshot(self): |
| 309 | obj, source = allocate_bytes(123) |
| 310 | |
| 311 | # take a snapshot |
| 312 | snapshot = tracemalloc.take_snapshot() |
| 313 | |
| 314 | # This can vary |
| 315 | self.assertGreater(snapshot.traces[1].traceback.total_nframe, 10) |
| 316 | |
| 317 | # write on disk |
| 318 | snapshot.dump(os_helper.TESTFN) |
| 319 | self.addCleanup(os_helper.unlink, os_helper.TESTFN) |
| 320 | |
| 321 | # load from disk |
| 322 | snapshot2 = tracemalloc.Snapshot.load(os_helper.TESTFN) |
| 323 | self.assertEqual(snapshot2.traces, snapshot.traces) |
| 324 | |
| 325 | # tracemalloc must be tracing memory allocations to take a snapshot |
| 326 | tracemalloc.stop() |
| 327 | with self.assertRaises(RuntimeError) as cm: |
| 328 | tracemalloc.take_snapshot() |
| 329 | self.assertEqual(str(cm.exception), |
| 330 | "the tracemalloc module must be tracing memory " |
| 331 | "allocations to take a snapshot") |
| 332 | |
| 333 | def test_snapshot_save_attr(self): |
| 334 | # take a snapshot with a new attribute |
nothing calls this directly
no test coverage detected