Hi, 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. -- Tomas Babej Associate Software Engeneer | Red Hat | Identity Management RHCE | Brno Site | IRC: tbabej | freeipa.org
From e1b9eac26f9d93a6a95c4f94fa68ee2fe68a16f3 Mon Sep 17 00:00:00 2001 From: Tomas Babej <tba...@redhat.com> Date: Mon, 14 Oct 2013 14:28:24 +0200 Subject: [PATCH] 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. --- ipatests/order_plugin.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ipatests/order_plugin.py b/ipatests/order_plugin.py index 9ecff32adb23249bb152b031654e2f0883826e57..4e447342e6ea6b6f814175d6d8fe08bb6d57c720 100644 --- a/ipatests/order_plugin.py +++ b/ipatests/order_plugin.py @@ -69,8 +69,26 @@ 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 class. If the method + is overriding a method from a parent ordered class, returns the + position of the method from the parent class. + """ + + # Check each *ordered* parent class for definition of func method + for parent_class in cls.__bases__: + if getattr(parent_class, '_order_plugin__ordered', False): + method = getattr(parent_class, func.__name__, None) + if method: + # If it was defined, return the position of the parent + # function + return method.func_code.co_firstlineno + + return 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 -- 1.8.3.1
_______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel