]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
forcibly clean out _sessions, _mapper_registry at test start to eliminate leftovers...
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 4 Feb 2008 20:35:25 +0000 (20:35 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 4 Feb 2008 20:35:25 +0000 (20:35 +0000)
test/orm/memusage.py

index 58c1a71c07e75d9aa33695731364d8da0da3e993..7f8392ed392282b514183eb8b839e465307384fa 100644 (file)
@@ -20,7 +20,9 @@ def profile_memory(func):
             gc.collect()
             samples.append(len(gc.get_objects()))
         print "sample gc sizes:", samples
+
         assert len(_sessions) == 0
+
         # TODO: this test only finds pure "growing" tests
         for i, x in enumerate(samples):
             if i < len(samples) - 1 and samples[i+1] <= x:
@@ -33,9 +35,14 @@ def profile_memory(func):
 def assert_no_mappers():
     clear_mappers()
     gc.collect()
-    assert len(_mapper_registry) == 0, len(_mapper_registry)
-    
-class MemUsageTest(AssertMixin):
+    assert len(_mapper_registry) == 0
+
+class EnsureZeroed(AssertMixin):
+    def setUp(self):
+        _sessions.clear()
+        _mapper_registry.clear()
+        
+class MemUsageTest(EnsureZeroed):
 
     def test_session(self):
         metadata = MetaData(testing.db)
@@ -139,6 +146,7 @@ class MemUsageTest(AssertMixin):
             for a in alist:
                 sess.delete(a)
             sess.flush()
+            sess.close()
             clear_mappers()
 
         metadata.create_all()