diff -r 71a1f53c8203 Lib/packaging/tests/support.py --- a/Lib/packaging/tests/support.py Wed Jul 06 07:31:38 2011 +0200 +++ b/Lib/packaging/tests/support.py Thu Jul 07 14:30:51 2011 +0200 @@ -37,7 +37,7 @@ from packaging import logger from packaging.dist import Distribution from packaging.tests import unittest -from test.support import requires_zlib, unlink +from test.support import requires_zlib, patch, unlink __all__ = ['LoggingCatcher', 'TempdirManager', 'EnvironRestorer', 'DummyCommand', 'unittest', 'create_distribution', @@ -266,6 +266,15 @@ return __wrap return _wrap +def patch_2to3(test_instance): + """Replaces `lib2to3.fixer_Base.BaseFix.set_filename()` with a + method that doesn't instantiate a new logger object to avoid + reference leaks.""" + def set_filename(self, filename): + self.filename = filename + from lib2to3.fixer_base import BaseFix + patch(test_instance, BaseFix, "set_filename", set_filename) + try: from test.support import skip_unless_symlink diff -r 71a1f53c8203 Lib/packaging/tests/test_mixin2to3.py --- a/Lib/packaging/tests/test_mixin2to3.py Wed Jul 06 07:31:38 2011 +0200 +++ b/Lib/packaging/tests/test_mixin2to3.py Thu Jul 07 14:30:51 2011 +0200 @@ -9,6 +9,10 @@ support.LoggingCatcher, unittest.TestCase): + def setUp(self): + super(Mixin2to3TestCase, self).setUp() + support.patch_2to3(self) + @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher') def test_convert_code_only(self): # used to check if code gets converted properly. diff -r 71a1f53c8203 Lib/packaging/tests/test_util.py --- a/Lib/packaging/tests/test_util.py Wed Jul 06 07:31:38 2011 +0200 +++ b/Lib/packaging/tests/test_util.py Thu Jul 07 14:30:51 2011 +0200 @@ -399,6 +399,7 @@ @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher') def test_run_2to3_on_code(self): + support.patch_2to3(self) content = "print 'test'" converted_content = "print('test')" file_handle = self.mktempfile() @@ -414,6 +415,7 @@ @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher') def test_run_2to3_on_doctests(self): + support.patch_2to3(self) # to check if text files containing doctests only get converted. content = ">>> print 'test'\ntest\n" converted_content = ">>> print('test')\ntest\n\n"