def test_snapshot(self):
    (obj, source) = allocate_bytes(123)
    snapshot = tracemalloc.take_snapshot()
    snapshot.dump(support.TESTFN)
    self.addCleanup(support.unlink, support.TESTFN)
    snapshot2 = tracemalloc.Snapshot.load(support.TESTFN)
    self.assertEqual(snapshot2.traces, snapshot.traces)
    tracemalloc.stop()
    with self.assertRaises(RuntimeError) as cm:
        tracemalloc.take_snapshot()
    self.assertEqual(str(cm.exception), 'the tracemalloc module must be tracing memory allocations to take a snapshot')
def test_snapshot(self):
    (obj, source) = allocate_bytes(123)
    snapshot = tracemalloc.take_snapshot()
    snapshot.dump(support.TESTFN)
    self.addCleanup(support.unlink, support.TESTFN)
    snapshot2 = tracemalloc.Snapshot.load(support.TESTFN)
    self.assertEqual(snapshot2.traces, snapshot.traces)
    tracemalloc.stop()
    with self.assertRaises(RuntimeError) as cm:
        tracemalloc.take_snapshot()
    self.assertEqual(str(cm.exception), 'the tracemalloc module must be tracing memory allocations to take a snapshot')