* [PATCHv2 0/2] OEQA loader improvment
@ 2017-02-27 7:44 mariano.lopez
2017-02-27 7:45 ` [PATCHv2 1/2] oeqa/core/loader.py: Give meaningful error when failed to load classes mariano.lopez
2017-02-27 7:45 ` [PATCHv2 2/2] oeqa/core/loader.py: Avoid importing tests with built-ins name mariano.lopez
0 siblings, 2 replies; 3+ messages in thread
From: mariano.lopez @ 2017-02-27 7:44 UTC (permalink / raw)
To: openembedded-core
From: Mariano Lopez <mariano.lopez@linux.intel.com>
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.
Change in v2:
- Rebased to current master
The following changes since commit 3c83b56309ab419f8cda72c0711479f60f61439a:
bitbake: fetch2/svn: change 'rsh' parameter to 'ssh' (2017-02-23 12:50:17 -0800)
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 | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
--
2.6.6
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCHv2 1/2] oeqa/core/loader.py: Give meaningful error when failed to load classes
2017-02-27 7:44 [PATCHv2 0/2] OEQA loader improvment mariano.lopez
@ 2017-02-27 7:45 ` mariano.lopez
2017-02-27 7:45 ` [PATCHv2 2/2] oeqa/core/loader.py: Avoid importing tests with built-ins name mariano.lopez
1 sibling, 0 replies; 3+ messages in thread
From: mariano.lopez @ 2017-02-27 7:45 UTC (permalink / raw)
To: openembedded-core
From: Mariano Lopez <mariano.lopez@linux.intel.com>
With this we get the class that is actually having the problem,
not just a TypeError with an unknown class causing the error.
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
---
meta/lib/oeqa/core/loader.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/meta/lib/oeqa/core/loader.py b/meta/lib/oeqa/core/loader.py
index a380325..b9ba923 100644
--- a/meta/lib/oeqa/core/loader.py
+++ b/meta/lib/oeqa/core/loader.py
@@ -171,11 +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" % \
- self.caseClass.__name__)
-
+ raise TypeError("Test %s is not derived from %s" % \
+ (testCaseClass.__name__, self.caseClass.__name__))
testCaseNames = self.getTestCaseNames(testCaseClass)
if not testCaseNames and hasattr(testCaseClass, 'runTest'):
--
2.6.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCHv2 2/2] oeqa/core/loader.py: Avoid importing tests with built-ins name
2017-02-27 7:44 [PATCHv2 0/2] OEQA loader improvment mariano.lopez
2017-02-27 7:45 ` [PATCHv2 1/2] oeqa/core/loader.py: Give meaningful error when failed to load classes mariano.lopez
@ 2017-02-27 7:45 ` mariano.lopez
1 sibling, 0 replies; 3+ messages in thread
From: mariano.lopez @ 2017-02-27 7:45 UTC (permalink / raw)
To: openembedded-core
From: Mariano Lopez <mariano.lopez@linux.intel.com>
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]
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
---
meta/lib/oeqa/core/loader.py | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/meta/lib/oeqa/core/loader.py b/meta/lib/oeqa/core/loader.py
index b9ba923..74f1117 100644
--- a/meta/lib/oeqa/core/loader.py
+++ b/meta/lib/oeqa/core/loader.py
@@ -216,6 +216,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(
@@ -227,6 +234,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(
--
2.6.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-27 15:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-27 7:44 [PATCHv2 0/2] OEQA loader improvment mariano.lopez
2017-02-27 7:45 ` [PATCHv2 1/2] oeqa/core/loader.py: Give meaningful error when failed to load classes mariano.lopez
2017-02-27 7:45 ` [PATCHv2 2/2] oeqa/core/loader.py: Avoid importing tests with built-ins name mariano.lopez
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.