From: Joshua Lock <joshua.g.lock@linux.intel.com>
To: jwang <jing.j.wang@intel.com>, openembedded-core@lists.openembedded.org
Subject: Re: [PATCH 2/4] meta: implement key baserunner features
Date: Thu, 15 Sep 2016 14:15:41 +0100 [thread overview]
Message-ID: <1473945341.3558.33.camel@linux.intel.com> (raw)
In-Reply-To: <1473729455-32649-2-git-send-email-jing.j.wang@intel.com>
On Tue, 2016-09-13 at 09:17 +0800, jwang wrote:
> From: zjh <junhuix.zhang@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@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
>
next prev parent reply other threads:[~2016-09-15 13:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-13 1:17 [PATCH 1/4] meta: introduce a small baserunner framework jwang
2016-09-13 1:17 ` [PATCH 2/4] meta: implement key baserunner features jwang
2016-09-15 13:15 ` Joshua Lock [this message]
2016-09-13 1:17 ` [PATCH 3/4] meta: use baserunner in oetest jwang
2016-09-15 13:15 ` Joshua Lock
2016-09-13 1:17 ` [PATCH 4/4] meta: modify runexported script to inherit the features from baserunner jwang
2016-09-15 13:15 ` [PATCH 1/4] meta: introduce a small baserunner framework Joshua Lock
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1473945341.3558.33.camel@linux.intel.com \
--to=joshua.g.lock@linux.intel.com \
--cc=jing.j.wang@intel.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox