summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorLucian Musat <georgex.l.musat@intel.com>2014-07-24 15:41:24 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-07-25 15:34:00 +0100
commit0c4dd0ad168e138ba96eaf27aa7e513aaf6704ee (patch)
tree04108e45fe1750a44b72ca1650f4cb8e1d466369 /meta/lib
parent0565d8bc17b061a8a6087f1667e10a3e3608c88e (diff)
downloadpoky-0c4dd0ad168e138ba96eaf27aa7e513aaf6704ee.tar.gz
oeqa: Refactor test skipping decorators to use the unittest result object
In order to make the test skipping decorators independent of the oeTest object we rely on the unittest result object to construct skip, fail and error lists used by these decorators. Created a new object getResults that analyses upper frames and retrieves the unittest result object instance, then return a list of failed, skipped and error tests. Also removed the oetest import from decorators.py because it was no longer required. (From OE-Core rev: 4d2d201158236bd4c72546cf8db88681ff921b11) Signed-off-by: Lucian Musat <georgex.l.musat@intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/oetest.py17
-rw-r--r--meta/lib/oeqa/utils/decorators.py40
2 files changed, 34 insertions, 23 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
index 0db6cb80a9..ecb8e53705 100644
--- a/meta/lib/oeqa/oetest.py
+++ b/meta/lib/oeqa/oetest.py
@@ -11,7 +11,6 @@ import os, re, mmap
11import unittest 11import unittest
12import inspect 12import inspect
13 13
14
15def loadTests(tc): 14def loadTests(tc):
16 15
17 # set the context object passed from the test class 16 # set the context object passed from the test class
@@ -36,24 +35,9 @@ def runTests(tc):
36 35
37 return result 36 return result
38 37
39
40class oeTest(unittest.TestCase): 38class oeTest(unittest.TestCase):
41 39
42 longMessage = True 40 longMessage = True
43 testFailures = []
44 testSkipped = []
45 testErrors = []
46
47 def run(self, result=None):
48 super(oeTest, self).run(result)
49
50 # we add to our own lists the results, we use those for decorators
51 if len(result.failures) > len(oeTest.testFailures):
52 oeTest.testFailures.append(str(result.failures[-1][0]).split()[0])
53 if len(result.skipped) > len(oeTest.testSkipped):
54 oeTest.testSkipped.append(str(result.skipped[-1][0]).split()[0])
55 if len(result.errors) > len(oeTest.testErrors):
56 oeTest.testErrors.append(str(result.errors[-1][0]).split()[0])
57 41
58 @classmethod 42 @classmethod
59 def hasPackage(self, pkg): 43 def hasPackage(self, pkg):
@@ -71,7 +55,6 @@ class oeTest(unittest.TestCase):
71 else: 55 else:
72 return False 56 return False
73 57
74
75class oeRuntimeTest(oeTest): 58class oeRuntimeTest(oeTest):
76 59
77 def __init__(self, methodName='runTest'): 60 def __init__(self, methodName='runTest'):
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index a0d94e6d24..439e80a42b 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -6,9 +6,34 @@
6# Most useful is skipUnlessPassed which can be used for 6# Most useful is skipUnlessPassed which can be used for
7# creating dependecies between two test methods. 7# creating dependecies between two test methods.
8 8
9from oeqa.oetest import *
10import logging 9import logging
11import sys 10import sys
11import unittest
12
13#get the "result" object from one of the upper frames provided that one of these upper frames is a unittest.case frame
14class getResults(object):
15 def __init__(self):
16 #dynamically determine the unittest.case frame and use it to get the name of the test method
17 upperf = sys._current_frames().values()[0]
18 while (upperf.f_globals['__name__'] != 'unittest.case'):
19 upperf = upperf.f_back
20 self.faillist = [ seq[0]._testMethodName for seq in upperf.f_locals['result'].failures ]
21 self.errorlist = [ seq[0]._testMethodName for seq in upperf.f_locals['result'].errors ]
22 #ignore the _ErrorHolder objects from the skipped tests list
23 self.skiplist = []
24 for seq in upperf.f_locals['result'].skipped:
25 try:
26 self.skiplist.append(seq[0]._testMethodName)
27 except: pass
28
29 def getFailList(self):
30 return self.faillist
31
32 def getErrorList(self):
33 return self.errorlist
34
35 def getSkipList(self):
36 return self.skiplist
12 37
13class skipIfFailure(object): 38class skipIfFailure(object):
14 39
@@ -17,7 +42,8 @@ class skipIfFailure(object):
17 42
18 def __call__(self,f): 43 def __call__(self,f):
19 def wrapped_f(*args): 44 def wrapped_f(*args):
20 if self.testcase in (oeTest.testFailures or oeTest.testErrors): 45 res = getResults()
46 if self.testcase in (res.getFailList() or res.getErrorList()):
21 raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) 47 raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase)
22 return f(*args) 48 return f(*args)
23 wrapped_f.__name__ = f.__name__ 49 wrapped_f.__name__ = f.__name__
@@ -30,7 +56,8 @@ class skipIfSkipped(object):
30 56
31 def __call__(self,f): 57 def __call__(self,f):
32 def wrapped_f(*args): 58 def wrapped_f(*args):
33 if self.testcase in oeTest.testSkipped: 59 res = getResults()
60 if self.testcase in res.getSkipList():
34 raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) 61 raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase)
35 return f(*args) 62 return f(*args)
36 wrapped_f.__name__ = f.__name__ 63 wrapped_f.__name__ = f.__name__
@@ -43,9 +70,10 @@ class skipUnlessPassed(object):
43 70
44 def __call__(self,f): 71 def __call__(self,f):
45 def wrapped_f(*args): 72 def wrapped_f(*args):
46 if self.testcase in oeTest.testSkipped or \ 73 res = getResults()
47 self.testcase in oeTest.testFailures or \ 74 if self.testcase in res.getSkipList() or \
48 self.testcase in oeTest.testErrors: 75 self.testcase in res.getFailList() or \
76 self.testcase in res.getErrorList():
49 raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) 77 raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase)
50 return f(*args) 78 return f(*args)
51 wrapped_f.__name__ = f.__name__ 79 wrapped_f.__name__ = f.__name__