Commits

Armin Rigo  committed 9c8f04b

Attempt to get rid of the occasional failure of test_methodcache.py.

  • Participants
  • Parent commits c48d25d

Comments (0)

Files changed (1)

File pypy/objspace/std/test/test_methodcache.py

 class AppTestMethodCaching(test_typeobject.AppTestTypeObject):
     spaceconfig = {"objspace.std.withmethodcachecounter": True}
 
+    def setup_class(cls):
+        # This is for the following tests, which are a bit fragile and
+        # historically have been failing once in a while.  With this hack,
+        # they are run up to 5 times in a row, saving the frame of the
+        # failed attempt.  This means occasional collisions should work
+        # differently during the retry.
+        cls.w_retry = cls.space.appexec([], """():
+            def retry(run):
+                keepalive = []
+                for i in range(4):
+                    try:
+                        return run()
+                    except AssertionError:
+                        import sys
+                        keepalive.append(sys.exc_info())
+                return run()
+            return retry
+        """)
+
     def test_mix_classes(self):
+      @self.retry
+      def run():
         import __pypy__
         class A(object):
             def f(self):
         assert sum(cache_counter) == 30
 
     def test_class_that_cannot_be_cached(self):
+      @self.retry
+      def run():
         import __pypy__
         class X:
             pass
         assert sum(cache_counter) == 20
  
     def test_change_methods(self):
+      @self.retry
+      def run():
         import __pypy__
         class A(object):
             def f(self):
         assert cache_counter == (17, 3)
 
     def test_subclasses(self):
+      @self.retry
+      def run():
         import __pypy__
         class A(object):
             def f(self):
         assert sum(cache_counter) == 30
   
     def test_many_names(self):
+      @self.retry
+      def run():
         import __pypy__
         for j in range(20):
             class A(object):
         assert e.foo == 3
 
     def test_custom_metaclass(self):
+      @self.retry
+      def run():
         import __pypy__
         for j in range(20):
             class MetaA(type):
             raise AssertionError("cache_counter = %r" % (cache_counter,))
 
     def test_mutate_class(self):
+      @self.retry
+      def run():
         import __pypy__
         class A(object):
             x = 1