Commits

shaib committed 4b817c5

Fix tests to use a real skipUnless whenever available

Comments (0)

Files changed (8)

 Andrew Godwin <andrew@aeracode.org>
 Simon Law
-Shai Berger
+Shai Berger <shai@platonix.com> # Sponsored by Healarium, http://healarium.com
 Andy McCurdy
 Simon Charette
 F. Gabriel Gosselin

south/tests/__init__.py

 
-import unittest
+#import unittest
 import os
 import sys
 from functools import wraps
 from django.conf import settings
 from south.hacks import hacks
 
+# Make sure skipping tests is available.
+try:
+    # easiest and best is unittest included in Django>=1.3
+    from django.utils import unittest
+except ImportError:
+    # earlier django... use unittest from stdlib
+    import unittest
+# however, skipUnless was only added in Python 2.7;
+# if not available, we need to do something else
+try:
+    skipUnless = unittest.skipUnless #@UnusedVariable
+except AttributeError:
+    def skipUnless(condition, message):
+        def decorator(testfunc):
+            @wraps(testfunc)
+            def wrapper(self):
+                if condition:
+                    # Apply method
+                    testfunc(self)
+                else:
+                    # The skip exceptions are not available either...
+                    print "Skipping", testfunc.__name__,"--", message
+            return wrapper
+        return decorator
+
 # Add the tests directory so fakeapp is on sys.path
 test_root = os.path.dirname(__file__)
 sys.path.append(test_root)
         if getattr(self, 'installed_apps', None):
             hacks.reset_installed_apps()
 
-# Make sure skipUnless is available.
-try:
-    # skipUnless added in Python 2.7;
-    from unittest import skipUnless
-except ImportError:
-    def skipUnless(condition, message):
-        def decorator(testfunc):
-            @wraps(testfunc)
-            def wrapper(self):
-                if condition:
-                    # Apply method
-                    testfunc(self)
-                else:
-                    # The skip exceptions are not available either...
-                    print "Skipping", testfunc.__name__,"--", message
-            return wrapper
-        return decorator
-
 
 # Try importing all tests if asked for (then we can run 'em)
 try:

south/tests/autodetection.py

-import unittest
+from south.tests import unittest
 
 from south.creator.changes import AutoChanges, InitialChanges
 from south.migration.base import Migrations

south/tests/db.py

 import datetime
-import unittest
 
 from south.db import db, generic
 from django.db import connection, models
 
-from south.tests import skipUnless        
+from south.tests import unittest, skipUnless        
 
 # Create a list of error classes from the various database libraries
 errors = []

south/tests/db_mysql.py

 # Additional MySQL-specific tests
 # Written by: F. Gabriel Gosselin <gabrielNOSPAM@evidens.ca>
 # Based on tests by: aarranz
-import unittest
+from south.tests import unittest
+
 
 from south.db import db, generic, mysql
 from django.db import connection, models

south/tests/freezer.py

-import unittest
+from south.tests import unittest
 
 from south.creator.freezer import model_dependencies
 from south.tests.fakeapp import models

south/tests/logger.py

 import logging
 import os
 import tempfile
-import unittest
+from south.tests import unittest
 import StringIO
 import sys
 

south/tests/logic.py

-import unittest
+from south.tests import unittest
 
 import datetime
 import sys