[PATCH] Fix TestPkgRelations failures with python3.

John Wright jsw at debian.org
Tue Aug 26 00:03:07 UTC 2014


The real implementation of assertWarns performs an iteration over
sys.modules.values(), which breaks because somehow the size of
sys.modules changes during the iteration.  I can't find where this
is happening (my best guess is there is some parallelism I can't find,
but even that is looking unlikely).  For now, overriding the real
implementation with our own fixes the test failure.
---
 tests/test_deb822.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index b2143a0..0bea1ed 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -920,14 +920,17 @@ Description: python modules to work with Debian-related data formats
 
 
 class TestPkgRelations(unittest.TestCase):
-    if sys.version < '3.2':
-        def assertWarns(self, warning, callable, *args, **kwds):
-            with warnings.catch_warnings(record=True) as warning_list:
-                warnings.simplefilter('always')
+    # TODO(jsw): Stop overriding this for Python versions that actually include
+    # assertWarns.  Unfortunately, that's not possible right now because for
+    # some reason sys.modules changes size during case.py's iteration of it in
+    # _AssertWarnsContext.__enter__ (python3.4).
+    def assertWarns(self, warning, callable, *args, **kwds):
+        with warnings.catch_warnings(record=True) as warning_list:
+            warnings.simplefilter('always')
 
-                result = callable(*args, **kwds)
+            result = callable(*args, **kwds)
 
-                self.assertTrue(any(item.category == warning for item in warning_list))
+            self.assertTrue(any(item.category == warning for item in warning_list))
 
     def assertPkgDictEqual(self, expected, actual):
         p1keys = sorted(expected.keys())
-- 
2.1.0




More information about the pkg-python-debian-maint mailing list