Skip to contentSkip to conversation

oeqa/runner: Fix subunit setupClass/setupModule failure handling

PATCH New Richard Purdie 1 participant 2 messages May 9, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 oeqa/runner: Fix subunit setupClass/setupModule failure handling

The string format for subunit setupClass/setupModule failures is slightly different, tweak the regex to correctly handle both cases.

---
 meta/lib/oeqa/core/runner.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/oeqa/core/runner.py +2 -2
index ca61de8cc0a..930620ea19f 100644
@@ -109,13 +109,13 @@ class OETestResult(_TestResult):
 
                 # When fails at module or class level the class name is passed as string
                 # so figure out to see if match
-                m = re.search(r"^setUpModule \((?P<module_name>.*)\)$", scase_str)
+                m = re.search(r"^setUpModule \((?P<module_name>.*)\).*$", scase_str)
                 if m:
                     if case.__class__.__module__ == m.group('module_name'):
                         found = True
                         break
 
-                m = re.search(r"^setUpClass \((?P<class_name>.*)\)$", scase_str)
+                m = re.search(r"^setUpClass \((?P<class_name>.*)\).*$", scase_str)
                 if m:
                     class_name = "%s.%s" % (case.__class__.__module__,
                                             case.__class__.__name__)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 oeqa/concurrenttest: Patch subunit module to handle classSetup failures

Currently setupClass errors were not being mapped back to the failing tests and they were hence being marked as UNKNOWN and the test statistics were inaccurate.

This is because whilst the errors were being encoded into the test results stream, the decoder doesn't cope with an error outside a testStart event.

We patch in an addError handler to the outsideTest parser so that this does get handled in a way similar to the non-concurrent case.

It would be nice if we didn't have to do this but there doesn't seem to be any other way to fix this other than forking subunit.

We also make a minor change so another of our changes can cope with tests without a start time.

---
 meta/lib/oeqa/core/utils/concurrencytest.py | 27 ++++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)
meta/lib/oeqa/core/utils/concurrencytest.py +23 -4
index 535b11e2d95..6bf7718863f 100644
@@ -21,6 +21,7 @@ import testtools
 import threading
 import time
 import io
+import subunit
 
 from queue import Queue
 from itertools import cycle
@@ -53,10 +54,11 @@ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult):
     def _add_result_with_semaphore(self, method, test, *args, **kwargs):
         self.semaphore.acquire()
         try:
-            self.result.starttime[test.id()] = self._test_start.timestamp()
-            self.result.threadprogress[self.threadnum].append(test.id())
-            totalprogress = sum(len(x) for x in self.result.threadprogress.values())
-            self.result.progressinfo[test.id()] = "%s: %s/%s %s/%s (%ss) (%s)" % (
+            if self._test_start:
+                self.result.starttime[test.id()] = self._test_start.timestamp()
+                self.result.threadprogress[self.threadnum].append(test.id())
+                totalprogress = sum(len(x) for x in self.result.threadprogress.values())
+                self.result.progressinfo[test.id()] = "%s: %s/%s %s/%s (%ss) (%s)" % (
                     self.threadnum,
                     len(self.result.threadprogress[self.threadnum]),
                     self.totalinprocess,
@@ -68,6 +70,23 @@ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult):
             self.semaphore.release()
         super(BBThreadsafeForwardingResult, self)._add_result_with_semaphore(method, test, *args, **kwargs)
 
+#
+# We have to patch subunit since it doesn't understand how to handle addError
+# outside of a running test case. This can happen if classSetUp() fails
+# for a class of tests. This unfortunately has horrible internal knowledge.
+#
+def outSideTestaddError(self, offset, line):
+    """An 'error:' directive has been read."""
+    test_name = line[offset:-1].decode('utf8')
+    self.parser._current_test = subunit.RemotedTestCase(test_name)
+    self.parser.current_test_description = test_name
+    self.parser._state = self.parser._reading_error_details
+    self.parser._reading_error_details.set_simple()
+    self.parser.subunitLineReceived(line)
+
+subunit._OutSideTest.addError = outSideTestaddError
+
+
 #
 # A dummy structure to add to io.StringIO so that the .buffer object
 # is available and accepts writes. This allows unittest with buffer=True
Signature · 1 line
2.20.1