OEQA loader improvement
cover OEQA loader improvement
From: Mariano Lopez <[email protected]>
The first adds more verbosity when a class doesn't inherit from the expected test class.
The second patch raises an error when trying to import a test with the same module name as a built-in module.
The following changes since commit e758547db9048d4aa1c1415d6af8072f519fae24:
nss: Fix nss-native so the checksum doesn't change with BUILD_ARCH (2017-02-09 10:52:03 +0000)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib mariano/bug10978
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=mariano/bug10978
Mariano Lopez (2):
oeqa/core/loader.py: Give meaningful error when failed to load classes oeqa/core/loader.py: Avoid importing tests with built-ins name
meta/lib/oeqa/core/loader.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
Signature · 1 line
2.6.6
PATCH 1/2 oeqa/core/loader.py: Give meaningful error when failed to load classes
From: Mariano Lopez <[email protected]>
With this we get the class that is actually having the problem, not just a TypeError with an unknown class causing the error.
--- meta/lib/oeqa/core/loader.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
meta/lib/oeqa/core/loader.py +4 -3
@@ -171,10 +171,11 @@ class OETestLoader(unittest.TestLoader): """ if issubclass(testCaseClass, unittest.suite.TestSuite): raise TypeError("Test cases should not be derived from TestSuite." \ - " Maybe you meant to derive from TestCase?") + " Maybe you meant to derive %s from TestCase?" \ + % testCaseClass.__name__) if not issubclass(testCaseClass, self.caseClass): - raise TypeError("Test cases need to be derived from %s" % \ - caseClass.__name__) + raise TypeError("Test %s is not derived from %s" % \ + (testCaseClass.__name__, self.caseClass.__name__)) testCaseNames = self.getTestCaseNames(testCaseClass)
Signature · 1 line
2.6.6
PATCH 2/2 oeqa/core/loader.py: Avoid importing tests with built-ins name
In reply to [email protected]From: Mariano Lopez <[email protected]>
If importing a test with the same name as a built-in module, it will silently import the built-in and check for tests in built-in module. This happened with syslog module in debian based machines, so add a raise to avoid this behavior.
[YOCTO #10978]
--- meta/lib/oeqa/core/loader.py | 11 +++++++++++ 1 file changed, 11 insertions(+)
meta/lib/oeqa/core/loader.py +11 -0
@@ -217,6 +217,13 @@ class OETestLoader(unittest.TestLoader): # use_load_tests deprecation via *args and **kws. See issue 16662. if sys.version_info >= (3,5): def loadTestsFromModule(self, module, *args, pattern=None, **kws): + """ + Returns a suite of all tests cases contained in module. + """ + if module.__name__ in sys.builtin_module_names: + msg = 'Tried to import %s test module but is a built-in' + raise ImportError(msg % module.__name__) + if not self.modules or "all" in self.modules or \ module.__name__ in self.modules: return super(OETestLoader, self).loadTestsFromModule(
@@ -228,6 +235,10 @@ class OETestLoader(unittest.TestLoader): """ Returns a suite of all tests cases contained in module. """ + if module.__name__ in sys.builtin_module_names: + msg = 'Tried to import %s test module but is a built-in' + raise ImportError(msg % module.__name__) + if not self.modules or "all" in self.modules or \ module.__name__ in self.modules: return super(OETestLoader, self).loadTestsFromModule(
Signature · 1 line
2.6.6