diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2017-05-26 15:37:32 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-02 13:36:13 +0100 |
commit | b4b9e22c40b7ce315d0286fe656581f81d965043 (patch) | |
tree | 9741e2f485ced305130ccd352151663cc6dc6cab /meta/lib/oeqa/core/context.py | |
parent | c7600278b6c39a311f822b1a7d39339bac3076c2 (diff) | |
download | poky-b4b9e22c40b7ce315d0286fe656581f81d965043.tar.gz |
oeqa/core: Move OETestContext.log{Summary, Details} into OETestResult
Those methods are used to write in the log the results so
it makes sense to have defined at OETestResult because
is a format of the result itself.
[YOCTO #11450]
(From OE-Core rev: 33a783f59ed4e232f41f8b09dfa7955f2ddc2f80)
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/core/context.py')
-rw-r--r-- | meta/lib/oeqa/core/context.py | 93 |
1 files changed, 3 insertions, 90 deletions
diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py index 2628651fa3..54958add07 100644 --- a/meta/lib/oeqa/core/context.py +++ b/meta/lib/oeqa/core/context.py | |||
@@ -7,10 +7,9 @@ import json | |||
7 | import time | 7 | import time |
8 | import logging | 8 | import logging |
9 | import collections | 9 | import collections |
10 | import re | ||
11 | 10 | ||
12 | from oeqa.core.loader import OETestLoader | 11 | from oeqa.core.loader import OETestLoader |
13 | from oeqa.core.runner import OETestRunner, xmlEnabled | 12 | from oeqa.core.runner import OETestRunner |
14 | 13 | ||
15 | class OETestContext(object): | 14 | class OETestContext(object): |
16 | loaderClass = OETestLoader | 15 | loaderClass = OETestLoader |
@@ -59,92 +58,6 @@ class OETestContext(object): | |||
59 | 58 | ||
60 | return result | 59 | return result |
61 | 60 | ||
62 | def logSummary(self, result, component, context_msg=''): | ||
63 | self.logger.info("SUMMARY:") | ||
64 | self.logger.info("%s (%s) - Ran %d test%s in %.3fs" % (component, | ||
65 | context_msg, result.testsRun, result.testsRun != 1 and "s" or "", | ||
66 | (self._run_end_time - self._run_start_time))) | ||
67 | |||
68 | if result.wasSuccessful(): | ||
69 | msg = "%s - OK - All required tests passed" % component | ||
70 | else: | ||
71 | msg = "%s - FAIL - Required tests failed" % component | ||
72 | skipped = len(self._results['skipped']) | ||
73 | if skipped: | ||
74 | msg += " (skipped=%d)" % skipped | ||
75 | self.logger.info(msg) | ||
76 | |||
77 | def _getDetailsNotPassed(self, case, type, desc): | ||
78 | found = False | ||
79 | |||
80 | for (scase, msg) in self._results[type]: | ||
81 | # XXX: When XML reporting is enabled scase is | ||
82 | # xmlrunner.result._TestInfo instance instead of | ||
83 | # string. | ||
84 | if xmlEnabled: | ||
85 | if case.id() == scase.test_id: | ||
86 | found = True | ||
87 | break | ||
88 | scase_str = scase.test_id | ||
89 | else: | ||
90 | if case == scase: | ||
91 | found = True | ||
92 | break | ||
93 | scase_str = str(scase) | ||
94 | |||
95 | # When fails at module or class level the class name is passed as string | ||
96 | # so figure out to see if match | ||
97 | m = re.search("^setUpModule \((?P<module_name>.*)\)$", scase_str) | ||
98 | if m: | ||
99 | if case.__class__.__module__ == m.group('module_name'): | ||
100 | found = True | ||
101 | break | ||
102 | |||
103 | m = re.search("^setUpClass \((?P<class_name>.*)\)$", scase_str) | ||
104 | if m: | ||
105 | class_name = "%s.%s" % (case.__class__.__module__, | ||
106 | case.__class__.__name__) | ||
107 | |||
108 | if class_name == m.group('class_name'): | ||
109 | found = True | ||
110 | break | ||
111 | |||
112 | if found: | ||
113 | return (found, msg) | ||
114 | |||
115 | return (found, None) | ||
116 | |||
117 | def logDetails(self): | ||
118 | self.logger.info("RESULTS:") | ||
119 | for case_name in self._registry['cases']: | ||
120 | case = self._registry['cases'][case_name] | ||
121 | |||
122 | result_types = ['failures', 'errors', 'skipped', 'expectedFailures'] | ||
123 | result_desc = ['FAILED', 'ERROR', 'SKIPPED', 'EXPECTEDFAIL'] | ||
124 | |||
125 | fail = False | ||
126 | desc = None | ||
127 | for idx, name in enumerate(result_types): | ||
128 | (fail, msg) = self._getDetailsNotPassed(case, result_types[idx], | ||
129 | result_desc[idx]) | ||
130 | if fail: | ||
131 | desc = result_desc[idx] | ||
132 | break | ||
133 | |||
134 | oeid = -1 | ||
135 | for d in case.decorators: | ||
136 | if hasattr(d, 'oeid'): | ||
137 | oeid = d.oeid | ||
138 | |||
139 | if fail: | ||
140 | self.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(), | ||
141 | oeid, desc)) | ||
142 | if msg: | ||
143 | self.logger.info(msg) | ||
144 | else: | ||
145 | self.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(), | ||
146 | oeid, 'PASSED')) | ||
147 | |||
148 | class OETestContextExecutor(object): | 61 | class OETestContextExecutor(object): |
149 | _context_class = OETestContext | 62 | _context_class = OETestContext |
150 | 63 | ||
@@ -227,8 +140,8 @@ class OETestContextExecutor(object): | |||
227 | self.tc = self._context_class(**self.tc_kwargs['init']) | 140 | self.tc = self._context_class(**self.tc_kwargs['init']) |
228 | self.tc.loadTests(self.module_paths, **self.tc_kwargs['load']) | 141 | self.tc.loadTests(self.module_paths, **self.tc_kwargs['load']) |
229 | rc = self.tc.runTests(**self.tc_kwargs['run']) | 142 | rc = self.tc.runTests(**self.tc_kwargs['run']) |
230 | self.tc.logSummary(rc, self.name) | 143 | rc.logSummary(self.name) |
231 | self.tc.logDetails() | 144 | rc.logDetails() |
232 | 145 | ||
233 | output_link = os.path.join(os.path.dirname(args.output_log), | 146 | output_link = os.path.join(os.path.dirname(args.output_log), |
234 | "%s-results.log" % self.name) | 147 | "%s-results.log" % self.name) |