Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef31657

Browse files
committed
Issue 10971: Make test_zipimport_support once again compatible with refleak hunting (reviewed by Georg Brandl)
1 parent 555f288 commit ef31657

2 files changed

Lines changed: 60 additions & 48 deletions

File tree

Lib/test/test_zipimport_support.py

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ def test_inspect_getsource_issue4223(self):
9393
os.remove(init_name)
9494
sys.path.insert(0, zip_name)
9595
import zip_pkg
96-
self.assertEqual(inspect.getsource(zip_pkg.foo), test_src)
96+
try:
97+
self.assertEqual(inspect.getsource(zip_pkg.foo), test_src)
98+
finally:
99+
del sys.modules["zip_pkg"]
97100

98101
def test_doctest_issue4197(self):
99102
# To avoid having to keep two copies of the doctest module's
@@ -128,53 +131,56 @@ def test_doctest_issue4197(self):
128131
os.remove(script_name)
129132
sys.path.insert(0, zip_name)
130133
import test_zipped_doctest
131-
# Some of the doc tests depend on the colocated text files
132-
# which aren't available to the zipped version (the doctest
133-
# module currently requires real filenames for non-embedded
134-
# tests). So we're forced to be selective about which tests
135-
# to run.
136-
# doctest could really use some APIs which take a text
137-
# string or a file object instead of a filename...
138-
known_good_tests = [
139-
test_zipped_doctest.SampleClass,
140-
test_zipped_doctest.SampleClass.NestedClass,
141-
test_zipped_doctest.SampleClass.NestedClass.__init__,
142-
test_zipped_doctest.SampleClass.__init__,
143-
test_zipped_doctest.SampleClass.a_classmethod,
144-
test_zipped_doctest.SampleClass.a_property,
145-
test_zipped_doctest.SampleClass.a_staticmethod,
146-
test_zipped_doctest.SampleClass.double,
147-
test_zipped_doctest.SampleClass.get,
148-
test_zipped_doctest.SampleNewStyleClass,
149-
test_zipped_doctest.SampleNewStyleClass.__init__,
150-
test_zipped_doctest.SampleNewStyleClass.double,
151-
test_zipped_doctest.SampleNewStyleClass.get,
152-
test_zipped_doctest.sample_func,
153-
test_zipped_doctest.test_DocTest,
154-
test_zipped_doctest.test_DocTestParser,
155-
test_zipped_doctest.test_DocTestRunner.basics,
156-
test_zipped_doctest.test_DocTestRunner.exceptions,
157-
test_zipped_doctest.test_DocTestRunner.option_directives,
158-
test_zipped_doctest.test_DocTestRunner.optionflags,
159-
test_zipped_doctest.test_DocTestRunner.verbose_flag,
160-
test_zipped_doctest.test_Example,
161-
test_zipped_doctest.test_debug,
162-
test_zipped_doctest.test_pdb_set_trace,
163-
test_zipped_doctest.test_pdb_set_trace_nested,
164-
test_zipped_doctest.test_testsource,
165-
test_zipped_doctest.test_trailing_space_in_test,
166-
test_zipped_doctest.test_DocTestSuite,
167-
test_zipped_doctest.test_DocTestFinder,
168-
]
169-
# These remaining tests are the ones which need access
170-
# to the data files, so we don't run them
171-
fail_due_to_missing_data_files = [
172-
test_zipped_doctest.test_DocFileSuite,
173-
test_zipped_doctest.test_testfile,
174-
test_zipped_doctest.test_unittest_reportflags,
175-
]
176-
for obj in known_good_tests:
177-
_run_object_doctest(obj, test_zipped_doctest)
134+
try:
135+
# Some of the doc tests depend on the colocated text files
136+
# which aren't available to the zipped version (the doctest
137+
# module currently requires real filenames for non-embedded
138+
# tests). So we're forced to be selective about which tests
139+
# to run.
140+
# doctest could really use some APIs which take a text
141+
# string or a file object instead of a filename...
142+
known_good_tests = [
143+
test_zipped_doctest.SampleClass,
144+
test_zipped_doctest.SampleClass.NestedClass,
145+
test_zipped_doctest.SampleClass.NestedClass.__init__,
146+
test_zipped_doctest.SampleClass.__init__,
147+
test_zipped_doctest.SampleClass.a_classmethod,
148+
test_zipped_doctest.SampleClass.a_property,
149+
test_zipped_doctest.SampleClass.a_staticmethod,
150+
test_zipped_doctest.SampleClass.double,
151+
test_zipped_doctest.SampleClass.get,
152+
test_zipped_doctest.SampleNewStyleClass,
153+
test_zipped_doctest.SampleNewStyleClass.__init__,
154+
test_zipped_doctest.SampleNewStyleClass.double,
155+
test_zipped_doctest.SampleNewStyleClass.get,
156+
test_zipped_doctest.sample_func,
157+
test_zipped_doctest.test_DocTest,
158+
test_zipped_doctest.test_DocTestParser,
159+
test_zipped_doctest.test_DocTestRunner.basics,
160+
test_zipped_doctest.test_DocTestRunner.exceptions,
161+
test_zipped_doctest.test_DocTestRunner.option_directives,
162+
test_zipped_doctest.test_DocTestRunner.optionflags,
163+
test_zipped_doctest.test_DocTestRunner.verbose_flag,
164+
test_zipped_doctest.test_Example,
165+
test_zipped_doctest.test_debug,
166+
test_zipped_doctest.test_pdb_set_trace,
167+
test_zipped_doctest.test_pdb_set_trace_nested,
168+
test_zipped_doctest.test_testsource,
169+
test_zipped_doctest.test_trailing_space_in_test,
170+
test_zipped_doctest.test_DocTestSuite,
171+
test_zipped_doctest.test_DocTestFinder,
172+
]
173+
# These remaining tests are the ones which need access
174+
# to the data files, so we don't run them
175+
fail_due_to_missing_data_files = [
176+
test_zipped_doctest.test_DocFileSuite,
177+
test_zipped_doctest.test_testfile,
178+
test_zipped_doctest.test_unittest_reportflags,
179+
]
180+
for obj in known_good_tests:
181+
_run_object_doctest(obj, test_zipped_doctest)
182+
finally:
183+
del sys.modules["test_zipped_doctest"]
178184

179185
def test_doctest_main_issue4197(self):
180186
test_src = textwrap.dedent("""\

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Build
3131

3232
- Issue #11121: Fix building with --enable-shared.
3333

34+
Tests
35+
-----
36+
37+
- Issue #10971:test_zipimport_support is once again compatible with the
38+
refleak hunter feature of test.regrtest.
39+
3440

3541
What's New in Python 3.2 Release Candidate 2?
3642
=============================================

0 commit comments

Comments
 (0)