8000 Improve compatibility of test.support with Py2 · TrendingTechnology/python-future@f9155c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9155c6

Browse files
committed
Improve compatibility of test.support with Py2
1 parent 371020e commit f9155c6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

future/standard_library/test/support.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import (absolute_import, division,
88
print_function, unicode_literals)
99
from future import utils
10-
from future.builtins import *
10+
from future.builtins import str, range, open, int, map, list
1111

1212

1313
# if __name__ != 'test.support':
@@ -955,7 +955,10 @@ def _filterwarnings(filters, quiet=False):
955955
frame = sys._getframe(2)
956956
registry = frame.f_globals.get('__warningregistry__')
957957
if registry:
958-
registry.clear()
958+
# Was: registry.clear()
959+
# Py2-compatible:
960+
for i in range(len(registry)):
961+
registry.pop()
959962
with warnings.catch_warnings(record=True) as w:
960963
# Set filter "always" to record all warnings. Because
961964
# test_warnings swap the module, we need to look up in
@@ -1709,7 +1712,12 @@ def modules_cleanup(oldmodules):
17091712
# globals will be set to None which will trip up the cached functions.
17101713
encodings = [(k, v) for k, v in sys.modules.items()
17111714
if k.startswith('encodings.')]
1712-
sys.modules.clear()
1715+
# Was:
1716+
# sys.modules.clear()
1717+
# Py2-compatible:
1718+
for i in range(len(sys.modules)):
1719+
sys.modules.pop()
1720+
17131721
sys.modules.update(encodings)
17141722
# XXX: This kind of problem can affect more than just encodings. In particular
17151723
# extension modules (such as _ssl) don't cope with reloading properly.

0 commit comments

Comments
 (0)
0