aboutsummaryrefslogtreecommitdiff
path: root/python/google/protobuf/internal/testing_refleaks.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/google/protobuf/internal/testing_refleaks.py')
-rw-r--r--python/google/protobuf/internal/testing_refleaks.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/python/google/protobuf/internal/testing_refleaks.py b/python/google/protobuf/internal/testing_refleaks.py
index 51a9af9e..c461a9f4 100644
--- a/python/google/protobuf/internal/testing_refleaks.py
+++ b/python/google/protobuf/internal/testing_refleaks.py
@@ -38,11 +38,15 @@ If sys.gettotalrefcount() is not available (because Python was built without
the Py_DEBUG option), then this module is a no-op and tests will run normally.
"""
-import copy_reg
import gc
import sys
try:
+ import copy_reg as copyreg #PY26
+except ImportError:
+ import copyreg
+
+try:
import unittest2 as unittest #PY26
except ImportError:
import unittest
@@ -74,7 +78,7 @@ class ReferenceLeakCheckerTestCase(unittest.TestCase):
# python_message.py registers all Message classes to some pickle global
# registry, which makes the classes immortal.
# We save a copy of this registry, and reset it before we could references.
- self._saved_pickle_registry = copy_reg.dispatch_table.copy()
+ self._saved_pickle_registry = copyreg.dispatch_table.copy()
# Run the test twice, to warm up the instance attributes.
super(ReferenceLeakCheckerTestCase, self).run(result=result)
@@ -97,8 +101,8 @@ class ReferenceLeakCheckerTestCase(unittest.TestCase):
result.addError(self, sys.exc_info())
def _getRefcounts(self):
- copy_reg.dispatch_table.clear()
- copy_reg.dispatch_table.update(self._saved_pickle_registry)
+ copyreg.dispatch_table.clear()
+ copyreg.dispatch_table.update(self._saved_pickle_registry)
# It is sometimes necessary to gc.collect() multiple times, to ensure
# that all objects can be collected.
gc.collect()