File tree Expand file tree Collapse file tree 4 files changed +31
-1
lines changed
Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ Christopher Gilling
3636Daniel Grana
3737Daniel Hahler
3838Daniel Nuri
39+ Daniel Wandschneider
3940Danielle Jenkins
4041Dave Hunt
4142David Díaz-Barquero
Original file line number Diff line number Diff line change 2626* Properly handle exceptions in ``multiprocessing `` tasks (`#1984 `_).
2727 Thanks `@adborden `_ for the report and `@nicoddemus `_ for the PR.
2828
29- *
29+ * Clean up unittest TestCase objects after tests are complete (`#1649 `_).
30+ Thanks `@d_b_w `_ for the report and PR.
3031
3132*
3233
3839.. _@okulynyak : https://github.com/okulynyak
3940.. _@matclab : https://github.com/matclab
4041.. _@gdyuldin : https://github.com/gdyuldin
42+ .. _@d_b_w : https://github.com/d_b_w
4143
4244.. _#442 : https://github.com/pytest-dev/pytest/issues/442
4345.. _#1976 : https://github.com/pytest-dev/pytest/issues/1976
4446.. _#1984 : https://github.com/pytest-dev/pytest/issues/1984
4547.. _#1998 : https://github.com/pytest-dev/pytest/issues/1998
4648.. _#2004 : https://github.com/pytest-dev/pytest/issues/2004
4749.. _#2005 : https://github.com/pytest-dev/pytest/issues/2005
50+ .. _#1649 : https://github.com/pytest-dev/pytest/issues/1649
4851
4952
50533.0.3
Original file line number Diff line number Diff line change @@ -94,6 +94,9 @@ def _fix_unittest_skip_decorator(self):
9494 def teardown (self ):
9595 if hasattr (self ._testcase , 'teardown_method' ):
9696 self ._testcase .teardown_method (self ._obj )
97+ # Allow garbage collection on TestCase instance attributes.
98+ self ._testcase = None
99+ self ._obj = None
97100
98101 def startTest (self , testcase ):
99102 pass
Original file line number Diff line number Diff line change 11from _pytest .main import EXIT_NOTESTSCOLLECTED
22import pytest
3+ import gc
34
45def test_simple_unittest (testdir ):
56 testpath = testdir .makepyfile ("""
@@ -134,6 +135,28 @@ def test_check(self):
134135 assert passed == 2
135136 assert passed + skipped + failed == 2
136137
138+ def test_teardown_issue1649 (testdir ):
139+ """
140+ Are TestCase objects cleaned up? Often unittest TestCase objects set
141+ attributes that are large and expensive during setUp.
142+
143+ The TestCase will not be cleaned up if the test fails, because it
144+ would then exist in the stackframe.
145+ """
146+ testpath = testdir .makepyfile ("""
147+ import unittest
148+ class TestCaseObjectsShouldBeCleanedUp(unittest.TestCase):
149+ def setUp(self):
150+ self.an_expensive_object = 1
151+ def test_demo(self):
152+ pass
153+
154+ """ )
155+ testdir .inline_run ("-s" , testpath )
156+ gc .collect ()
157+ for obj in gc .get_objects ():
158+ assert type (obj ).__name__ != 'TestCaseObjectsShouldBeCleanedUp'
159+
137160@pytest .mark .skipif ("sys.version_info < (2,7)" )
138161def test_unittest_skip_issue148 (testdir ):
139162 testpath = testdir .makepyfile ("""
You can’t perform that action at this time.
0 commit comments