diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-07-19 20:30:14 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-07-19 20:30:14 +0200 |
| commit | 6d52844b9b3c0bd18eea03ac9dc499782b84c36b (patch) | |
| tree | 8df4e2609d5fc8b1b1ea68ff422d90e776693e8c /django | |
| parent | a269ea4fe0a9a7195f1bd8bf5d462f48c226d525 (diff) | |
Fixed #18551 -- Enabled skipIfDBFeature/skipUnlessDBFeature to decorate a class
Thanks Tim Graham for the review and improved patch.
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/testcases.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index d0442360ac..6f3f1c00e4 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -879,10 +879,19 @@ class TestCase(TransactionTestCase): self.atomics[db_name].__exit__(None, None, None) +class CheckCondition(object): + """Descriptor class for deferred condition checking""" + def __init__(self, cond_func): + self.cond_func = cond_func + + def __get__(self, obj, objtype): + return self.cond_func() + + def _deferredSkip(condition, reason): def decorator(test_func): if not (isinstance(test_func, type) and - issubclass(test_func, TestCase)): + issubclass(test_func, unittest.TestCase)): @wraps(test_func) def skip_wrapper(*args, **kwargs): if condition(): @@ -890,7 +899,9 @@ def _deferredSkip(condition, reason): return test_func(*args, **kwargs) test_item = skip_wrapper else: + # Assume a class is decorated test_item = test_func + test_item.__unittest_skip__ = CheckCondition(condition) test_item.__unittest_skip_why__ = reason return test_item return decorator |
