[OE-core] [PATCH 2/4] meta: implement key baserunner features
Joshua Lock
joshua.g.lock at linux.intel.com
Thu Sep 15 13:15:41 UTC 2016
On Tue, 2016-09-13 at 09:17 +0800, jwang wrote:
> From: zjh <junhuix.zhang at intel.com>
>
> Baserunner contains three features:
> 1. load cases from a manifest file
> 2. load cases from a package such as "oeqa.runtime"
> 3. create runner engine based on pyunit textrunner
I think this and 1/4 should probably be squashed together?
>
> Signed-off-by: zjh <junhuix.zhang at intel.com>
> ---
> meta/lib/base/baserunner.py | 44
> ++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 38 insertions(+), 6 deletions(-)
>
> diff --git a/meta/lib/base/baserunner.py
> b/meta/lib/base/baserunner.py
> index 56b838e..d59872f 100755
> --- a/meta/lib/base/baserunner.py
> +++ b/meta/lib/base/baserunner.py
> @@ -31,30 +31,62 @@ class FakeOptions(object):
> class TestRunnerBase(object):
> '''test runner base '''
> def __init__(self, context=None):
> - self.tclist = []
> + self.testslist = []
> self.runner = None
> self.context = context if context else TestContext()
> + self.test_options = None
> self.test_result = None
> self.run_time = None
>
> + def __del__(self):
> + """
> + Because unittest.TestCase is a class object, it will exist
> as long as the python virtual machine process.
> + So tc can't be released if we don't release them explicitly.
> + """
> + if hasattr(unittest.TestCase, "tc"):
> + delattr(unittest.TestCase, "tc")
> +
> + @staticmethod
> + def get_tc_from_manifest(fname):
> + '''get tc list from manifest format '''
> + with open(fname, "r") as f:
> + tclist = [n.strip() for n in f.readlines() \
> + if n.strip() and not
> n.strip().startswith('#')]
> + return tclist
It might be nice to handle open() failing here? If open() fails we're
trying to return an undefined instance.
>
> def configure(self, options=FakeOptions()):
> '''configure before testing'''
> - pass
> + self.test_options = options
> + self.runner = unittest.TextTestRunner(stream=sys.stderr, \
There's no need for a backslash here, we can rely on Python's implied
continuation.
> + verbosity=2)
>
> def result(self):
> '''output test result '''
> - pass
> + return self.test_result
>
> def loadtest(self, names=None):
> '''load test suite'''
> - pass
> + if names is None:
It's much more idiomatic to write these like:
if not names:
> + names = self.testslist
> + testloader = unittest.TestLoader()
> + tclist = []
> + for name in names:
> + tset = testloader.loadTestsFromName(name)
> + if tset.countTestCases() > 0:
> + tclist.append(tset)
> + elif tset._tests == []:
variable names prefixed with an underscore are, by convention,
internal/private to the object.
Is there a case where countTestCases() might not be > 0 and _tests[] !=
[] ? i.e. can we just use an else here?
> + tclist.append(testloader.discover(name, "[!_]*.py",
> os.path.curdir))
> + return testloader.suiteClass(tclist)
>
> def runtest(self, testsuite):
> '''run test suite'''
> - pass
> + starttime = time.time()
> + self.test_result = self.runner.run(testsuite)
> + self.run_time = time.time() - starttime
>
> def start(self, testsuite):
> '''start testing'''
> - pass
> + setattr(unittest.TestCase, "tc", self.context)
> + self.runtest(testsuite)
> + self.result()
>
> --
> 2.1.4
>
More information about the Openembedded-core
mailing list