summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2020-03-11 08:28:23 -0500
committerJason Madden <jamadden@gmail.com>2020-03-18 12:26:35 -0500
commit7afd59d869e3391ce27a4a07ad0931eb5e7910a1 (patch)
treebd71f467d38458772643af65082e53f322b3f7be /src
parent5f4bb3f8ec7798b146c007041ff60aac2ca0566e (diff)
downloadzope-interface-7afd59d869e3391ce27a4a07ad0931eb5e7910a1.tar.gz
Fix tests when zope.component is also importable.
Diffstat (limited to 'src')
-rw-r--r--src/zope/interface/tests/__init__.py22
-rw-r--r--src/zope/interface/tests/test_interface.py3
2 files changed, 24 insertions, 1 deletions
diff --git a/src/zope/interface/tests/__init__.py b/src/zope/interface/tests/__init__.py
index c37dffc..8b9ef25 100644
--- a/src/zope/interface/tests/__init__.py
+++ b/src/zope/interface/tests/__init__.py
@@ -31,3 +31,25 @@ class OptimizationTestMixin(object):
self.assertIsNot(used, fallback)
else:
self.assertIs(used, fallback)
+
+# Be sure cleanup functionality is available; classes that use the adapter hook
+# need to be sure to subclass ``CleanUp``.
+#
+# If zope.component is installed and imported when we run our tests
+# (import chain:
+# zope.testrunner->zope.security->zope.location->zope.component.api)
+# it adds an adapter hook that uses its global site manager. That can cause
+# leakage from one test to another unless its cleanup hooks are run. The symptoms can
+# be odd, especially if one test used C objects and the next used the Python
+# implementation. (For example, you can get strange TypeErrors or find inexplicable
+# comparisons being done.)
+try:
+ from zope.testing import cleanup
+except ImportError:
+ class CleanUp(object):
+ def cleanUp(self):
+ pass
+
+ setUp = tearDown = cleanUp
+else:
+ CleanUp = cleanup.CleanUp
diff --git a/src/zope/interface/tests/test_interface.py b/src/zope/interface/tests/test_interface.py
index c6b21ad..e7ae547 100644
--- a/src/zope/interface/tests/test_interface.py
+++ b/src/zope/interface/tests/test_interface.py
@@ -25,6 +25,7 @@ import unittest
from zope.interface._compat import _skip_under_py3k
from zope.interface.tests import OptimizationTestMixin
+from zope.interface.tests import CleanUp
_marker = object()
@@ -254,7 +255,7 @@ class SpecificationBasePyTests(GenericSpecificationBaseTests):
self.assertTrue(sb.providedBy(object()))
-class InterfaceBaseTestsMixin(object):
+class InterfaceBaseTestsMixin(CleanUp):
# Tests for both C and Python implementation
def _getTargetClass(self):