From 18c72d59e0807dae75ac2c34890d08c1e0972d0a Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Mon, 12 Sep 2016 22:06:31 -0400 Subject: Fixed #27214 -- Made skip db features decorators respect wrapping order and inheritance. --- django/test/testcases.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'django') diff --git a/django/test/testcases.py b/django/test/testcases.py index 8fd84b1423..be5720a80b 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1083,11 +1083,23 @@ class TestCase(TransactionTestCase): class CheckCondition(object): """Descriptor class for deferred condition checking""" - def __init__(self, cond_func): - self.cond_func = cond_func + def __init__(self, *conditions): + self.conditions = conditions + + def add_condition(self, condition, reason): + return self.__class__(*self.conditions + ((condition, reason),)) def __get__(self, instance, cls=None): - return self.cond_func() + # Trigger access for all bases. + if any(getattr(base, '__unittest_skip__', False) for base in cls.__bases__): + return True + for condition, reason in self.conditions: + if condition(): + # Override this descriptor's value and set the skip reason. + cls.__unittest_skip__ = True + cls.__unittest_skip_why__ = reason + return True + return False def _deferredSkip(condition, reason): @@ -1103,8 +1115,13 @@ def _deferredSkip(condition, reason): else: # Assume a class is decorated test_item = test_func - test_item.__unittest_skip__ = CheckCondition(condition) - test_item.__unittest_skip_why__ = reason + # Retrieve the possibly existing value from the class's dict to + # avoid triggering the descriptor. + skip = test_func.__dict__.get('__unittest_skip__') + if isinstance(skip, CheckCondition): + test_item.__unittest_skip__ = skip.add_condition(condition, reason) + elif skip is not True: + test_item.__unittest_skip__ = CheckCondition((condition, reason)) return test_item return decorator -- cgit v1.3