diff options
Diffstat (limited to 'meta/lib/oeqa/oetest.py')
| -rw-r--r-- | meta/lib/oeqa/oetest.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index 4773bdd4d8..9724325083 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py | |||
| @@ -12,9 +12,32 @@ import unittest | |||
| 12 | import inspect | 12 | import inspect |
| 13 | import subprocess | 13 | import subprocess |
| 14 | import bb | 14 | import bb |
| 15 | from oeqa.utils.decorators import LogResults | 15 | from oeqa.utils.decorators import LogResults, gettag |
| 16 | from sys import exc_info, exc_clear | 16 | from sys import exc_info, exc_clear |
| 17 | 17 | ||
| 18 | def getVar(obj): | ||
| 19 | #extend form dict, if a variable didn't exists, need find it in testcase | ||
| 20 | class VarDict(dict): | ||
| 21 | def __getitem__(self, key): | ||
| 22 | return gettag(obj, key) | ||
| 23 | return VarDict() | ||
| 24 | |||
| 25 | def checkTags(tc, tagexp): | ||
| 26 | return eval(tagexp, None, getVar(tc)) | ||
| 27 | |||
| 28 | |||
| 29 | def filterByTagExp(testsuite, tagexp): | ||
| 30 | if not tagexp: | ||
| 31 | return testsuite | ||
| 32 | caseList = [] | ||
| 33 | for each in testsuite: | ||
| 34 | if not isinstance(each, unittest.BaseTestSuite): | ||
| 35 | if checkTags(each, tagexp): | ||
| 36 | caseList.append(each) | ||
| 37 | else: | ||
| 38 | caseList.append(filterByTagExp(each, tagexp)) | ||
| 39 | return testsuite.__class__(caseList) | ||
| 40 | |||
| 18 | def loadTests(tc, type="runtime"): | 41 | def loadTests(tc, type="runtime"): |
| 19 | if type == "runtime": | 42 | if type == "runtime": |
| 20 | # set the context object passed from the test class | 43 | # set the context object passed from the test class |
| @@ -29,6 +52,7 @@ def loadTests(tc, type="runtime"): | |||
| 29 | testloader = unittest.TestLoader() | 52 | testloader = unittest.TestLoader() |
| 30 | testloader.sortTestMethodsUsing = None | 53 | testloader.sortTestMethodsUsing = None |
| 31 | suites = [testloader.loadTestsFromName(name) for name in tc.testslist] | 54 | suites = [testloader.loadTestsFromName(name) for name in tc.testslist] |
| 55 | suites = filterByTagExp(suites, getattr(tc, "tagexp", None)) | ||
| 32 | 56 | ||
| 33 | def getTests(test): | 57 | def getTests(test): |
| 34 | '''Return all individual tests executed when running the suite.''' | 58 | '''Return all individual tests executed when running the suite.''' |
| @@ -86,6 +110,8 @@ def runTests(tc, type="runtime"): | |||
| 86 | 110 | ||
| 87 | suite = loadTests(tc, type) | 111 | suite = loadTests(tc, type) |
| 88 | bb.note("Test modules %s" % tc.testslist) | 112 | bb.note("Test modules %s" % tc.testslist) |
| 113 | if hasattr(tc, "tagexp") and tc.tagexp: | ||
| 114 | bb.note("Filter test cases by tags: %s" % tc.tagexp) | ||
| 89 | bb.note("Found %s tests" % suite.countTestCases()) | 115 | bb.note("Found %s tests" % suite.countTestCases()) |
| 90 | runner = unittest.TextTestRunner(verbosity=2) | 116 | runner = unittest.TextTestRunner(verbosity=2) |
| 91 | result = runner.run(suite) | 117 | result = runner.run(suite) |
