diff options
author | John Szakmeister <john@szakmeister.net> | 2014-02-17 10:42:47 -0500 |
---|---|---|
committer | John Szakmeister <john@szakmeister.net> | 2014-02-20 04:59:21 -0500 |
commit | b65c42fd4e8ade68a5db00d8f089cf3285bd127e (patch) | |
tree | 0dfc64116ed49b08c24837c053d72dea9fed1ab9 /nose | |
parent | 129bd91e222a0ef973ea962eb539763748b54a84 (diff) | |
download | nose-b65c42fd4e8ade68a5db00d8f089cf3285bd127e.tar.gz |
Fix #771: attr plugin is broken when parent overrides child method
The issue is when the parent and child have different attributes, and
the parent method was being bypassed because of the attribute selection.
In this case, Nose would incorrectly use the version from the base
class, even though it was supposed to skip the method entirely.
To fix this, we need simply need to stop digging through base classes.
The dir() method returns a flattened set of methods, so there's no need
to iterate through the base classes trying to dig up all the methods.
Moreover, it leads to false positives since we were not keeping track of
methods seen on the parent classes. As a result, we'd incorrectly
select a test for inclusion (using attributes), or we'd pick up a method
that we should've ignored (like runTest in a Twisted test case).
Thanks to Thomas Grainger for providing a test case!
Diffstat (limited to 'nose')
-rw-r--r-- | nose/loader.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/nose/loader.py b/nose/loader.py index 480c898..4152a12 100644 --- a/nose/loader.py +++ b/nose/loader.py @@ -104,7 +104,7 @@ class TestLoader(unittest.TestLoader): """ if self.config.getTestCaseNamesCompat: return unittest.TestLoader.getTestCaseNames(self, testCaseClass) - + def wanted(attr, cls=testCaseClass, sel=self.selector): item = getattr(cls, attr, None) if isfunction(item): @@ -112,11 +112,9 @@ class TestLoader(unittest.TestLoader): elif not ismethod(item): return False return sel.wantMethod(item) + cases = filter(wanted, dir(testCaseClass)) - for base in testCaseClass.__bases__: - for case in self.getTestCaseNames(base): - if case not in cases: - cases.append(case) + # add runTest if nothing else picked if not cases and hasattr(testCaseClass, 'runTest'): cases = ['runTest'] |