--- oe-selftest.origin 2015-06-09 16:01:24.048627485 +0800 +++ oe-selftest 2015-06-15 14:44:36.680849828 +0800 @@ -38,6 +38,13 @@ from oeqa.utils.commands import runCmd, get_bb_var, get_test_layer from oeqa.selftest.base import oeSelfTest +# add test cases location into the python searching path +for l in get_bb_var('BBPATH').split(':'): + if os.path.exists(os.path.abspath(os.path.join(l, 'lib/oeqa/selftest'))): + sys.path.insert(0, os.path.abspath(os.path.join(l, 'lib'))) +# reloading this package is necessary due to "sys.path" updated +reload(oeqa.selftest) + def logger_create(): log = logging.getLogger("selftest") log.setLevel(logging.DEBUG) @@ -127,11 +134,18 @@ for x in exclusive_modules: testslist.append('oeqa.selftest.' + x) if not testslist: - testpath = os.path.abspath(os.path.dirname(oeqa.selftest.__file__)) - files = sorted([f for f in os.listdir(testpath) if f.endswith('.py') and not (f.startswith('_') and not include_hidden) and not f.startswith('__') and f != 'base.py']) - for f in files: - module = 'oeqa.selftest.' + f[:-3] - testslist.append(module) + # add test cases to "testslist" for *every* subfolder under "oeqa/selftest/" + def _addtest(args, dname, fnames): + if (os.path.basename(dname) != 'files'): # 'files' folder is ignored. it is for test data. + d=dname[args[0]:].replace('/','.') # d is the sub-package name. eg: "oeqa/selftest/cfg/mytest.py", d=cfg + for f in fnames: + if (f.endswith('.py') and not (f.startswith('_') and not include_hidden) and not f.startswith('__') and f != 'base.py'): + testslist.append('oeqa.selftest'+d+'.'+f[:-3]) # test is added as "oeqa.selftest.cfg.mytest" + # detect test cases from all layers that added to "BBPATH" + for l in get_bb_var('BBPATH').split(':'): + testpath = os.path.join(l, 'lib', 'oeqa', 'selftest') + if os.path.exists(testpath): + os.path.walk(testpath, _addtest, [len(testpath)]) return testslist @@ -146,7 +160,9 @@ log.info('Listing all available test modules:') testslist = get_tests(include_hidden=True) for test in testslist: - module = test.split('.')[-1] + # list test with its sub-package name, relative to oeqa.selftest. + # eg: "oeqa.selftest.cfg.mytest" is listed as "cfg.mytest" + module = test.split('.',2)[-1] info = '' if module.startswith('_'): info = ' (hidden)'