It seems unittest.TestSuite holds references to unittest.TestCase instances after the test runs, until the test suite finishes. In a large suite, where the TestCase instances consume memory during execution, that can lead to exhausting all available memory and the OS killing the test process.<div>
<br></div><div>What do you think of a change like this?</div><div><br></div><div><div>$ hg diff</div><div>diff -r 3bd55ec317a7 Lib/unittest/suite.py</div><div>--- a/Lib/unittest/suite.py<span class="Apple-tab-span" style="white-space:pre"> </span>Thu Aug 01 23:57:21 2013 +0200</div>
<div>+++ b/Lib/unittest/suite.py<span class="Apple-tab-span" style="white-space:pre">   </span>Fri Aug 02 07:42:22 2013 -0400</div><div>@@ -90,7 +90,12 @@</div><div>         if getattr(result, '_testRunEntered', False) is False:</div>
<div>             result._testRunEntered = topLevel = True</div><div> </div><div>-        for test in self:</div><div>+        while True:</div><div>+            try:</div><div>+                test = self._tests.pop(0)</div>
<div>+            except IndexError:</div><div>+                break</div><div>+</div><div>             if result.shouldStop:</div><div>                 break</div><div> </div></div><div>See also the conversation on django-developers[1] that led me here.</div>
<div><br></div><div>[1]: <a href="https://groups.google.com/forum/#!topic/django-developers/XUMetDSGVT0">https://groups.google.com/forum/#!topic/django-developers/XUMetDSGVT0</a></div><div><div><br></div>-- <br>Matt McClure<br>
<a href="http://matthewlmcclure.com" target="_blank">http://matthewlmcclure.com</a><br><a href="http://www.mapmyfitness.com/profile/matthewlmcclure" target="_blank">http://www.mapmyfitness.com/profile/matthewlmcclure</a><br>

</div>