diff options
author | zjh <junhuix.zhang@intel.com> | 2015-09-02 15:39:54 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-09-03 13:55:39 +0100 |
commit | 085589b1018ba4d950baf7bcfb499be02c1b29fc (patch) | |
tree | 4460fb8f66508e2403b4a0c7ac25b6f2d90b6e75 /meta/lib/oeqa/oetest.py | |
parent | e0af4b2c8f8e29ac6f8eccef401c7c004355359d (diff) | |
download | openembedded-core-contrib-085589b1018ba4d950baf7bcfb499be02c1b29fc.tar.gz |
testimage: filter proper test cases by tags
If a test case is decorate by oeqa.utils.decorators.tag, this case will
by add a tag, testrunner will filter these tags by TEST_SUITES_TAGS
[YOCTO #7849]
Signed-off-by: zjh <junhuix.zhang@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
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 import inspect import subprocess import bb -from oeqa.utils.decorators import LogResults +from oeqa.utils.decorators import LogResults, gettag from sys import exc_info, exc_clear +def getVar(obj): + #extend form dict, if a variable didn't exists, need find it in testcase + class VarDict(dict): + def __getitem__(self, key): + return gettag(obj, key) + return VarDict() + +def checkTags(tc, tagexp): + return eval(tagexp, None, getVar(tc)) + + +def filterByTagExp(testsuite, tagexp): + if not tagexp: + return testsuite + caseList = [] + for each in testsuite: + if not isinstance(each, unittest.BaseTestSuite): + if checkTags(each, tagexp): + caseList.append(each) + else: + caseList.append(filterByTagExp(each, tagexp)) + return testsuite.__class__(caseList) + def loadTests(tc, type="runtime"): if type == "runtime": # set the context object passed from the test class @@ -29,6 +52,7 @@ def loadTests(tc, type="runtime"): testloader = unittest.TestLoader() testloader.sortTestMethodsUsing = None suites = [testloader.loadTestsFromName(name) for name in tc.testslist] + suites = filterByTagExp(suites, getattr(tc, "tagexp", None)) def getTests(test): '''Return all individual tests executed when running the suite.''' @@ -86,6 +110,8 @@ def runTests(tc, type="runtime"): suite = loadTests(tc, type) bb.note("Test modules %s" % tc.testslist) + if hasattr(tc, "tagexp") and tc.tagexp: + bb.note("Filter test cases by tags: %s" % tc.tagexp) bb.note("Found %s tests" % suite.countTestCases()) runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) |