From e0bd235ffa78e74cdeccac5dabedd66487fd124f Mon Sep 17 00:00:00 2001 From: Paul McMillan Date: Fri, 2 Jul 2010 19:06:53 +0000 Subject: [PATCH] [soc2010/test-refactor] Added skipIfDBEngine() decorator to django.test git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/test-refactor@13416 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/test/__init__.py | 1 + django/test/utils.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/django/test/__init__.py b/django/test/__init__.py index 957b293e12..57f6014550 100644 --- a/django/test/__init__.py +++ b/django/test/__init__.py @@ -4,3 +4,4 @@ Django Unit Test and Doctest framework. from django.test.client import Client from django.test.testcases import TestCase, TransactionTestCase +from django.test.utils import skipIfDBEngine diff --git a/django/test/utils.py b/django/test/utils.py index b6ab39901b..453ee3bf94 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -2,9 +2,11 @@ import sys, time, os from django.conf import settings from django.core import mail from django.core.mail.backends import locmem +from django.db import DEFAULT_DB_ALIAS from django.test import signals from django.template import Template from django.utils.translation import deactivate +from django.utils.unittest import skipIf class ContextList(list): """A wrapper that provides direct key access to context items contained @@ -77,3 +79,14 @@ def get_runner(settings): test_module = __import__(test_module_name, {}, {}, test_path[-1]) test_runner = getattr(test_module, test_path[-1]) return test_runner + +def skipIfDBEngine(engine, reason=None): + """ + Decorator to skip tests on a given database engine. + + Note that you can pass a single engine or an iterable here + """ + if not reason: + reason = "not supported on this database" + return skipIf(settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] in engine, + reason)