diff options
author | Tomas Babej <tbabej@redhat.com> | 2013-10-14 14:28:24 +0200 |
---|---|---|
committer | Petr Viktorin <pviktori@redhat.com> | 2013-10-17 10:48:17 +0200 |
commit | 76694f161089a538b37191280c82454d34bebcb9 (patch) | |
tree | 3eb993f364644cd2120a3eb61c351c79cffe58ec /ipatests | |
parent | 1b13a950751d086ce09c9552c2ce887e9d1d9bec (diff) | |
download | freeipa-76694f161089a538b37191280c82454d34bebcb9.tar.gz freeipa-76694f161089a538b37191280c82454d34bebcb9.tar.xz freeipa-76694f161089a538b37191280c82454d34bebcb9.zip |
ipatests: Extend the order plugin to properly handle inheritance
When trying to create a new ordered test case by inheriting
from already defined test case, by overriding few of its methods,
the execution order of the tests is as follows:
- first all non-overriden test methods from the parent test class
- then all overriden tests methods
This patch makes sure that methods are executed in the logical order,
that is, the order defined in the parent class.
Diffstat (limited to 'ipatests')
-rw-r--r-- | ipatests/order_plugin.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/ipatests/order_plugin.py b/ipatests/order_plugin.py index 9ecff32ad..7b114a567 100644 --- a/ipatests/order_plugin.py +++ b/ipatests/order_plugin.py @@ -69,8 +69,31 @@ class OrderTests(Plugin): return False return loader.selector.wantMethod(item) + def sort_with_respect_to_overriding(func): + """ + Sorts the methods in respect with the parent classes. + + The methods are sorted with respect to the inheritance chain, + methods that were defined in the same class are sorted by the line + number on which they were defined. + """ + + # Check each *ordered* class in MRO for definition of func method + for i, parent_class in enumerate(reversed(cls.mro())): + if getattr(parent_class, '_order_plugin__ordered', False): + method = getattr(parent_class, func.__name__, None) + if method: + # This sorts methods as tuples (position of the class + # in the inheritance chain, position of the method + # within that class) + return 0, i, method.func_code.co_firstlineno + + # Weird case fallback + # Method name not in any of the classes in MRO, run it last + return 1, func.func_code.co_firstlineno + methods = [getattr(cls, case) for case in dir(cls) if wanted(case)] - methods.sort(key=lambda m: m.func_code.co_firstlineno) + methods.sort(key=sort_with_respect_to_overriding) cases = [loader.makeTest(m, cls) for m in methods] return cases |