summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-05-18 10:21:31 +0200
committerAndrew Godwin <andrew@aeracode.org>2013-05-18 10:21:31 +0200
commitb31eea069cf9bc801c82a975307a9173527d78f2 (patch)
treed3fb5b6e5ae4e6d4293786b94a193ed4f9fc4959 /tests
parent76d93a52cd56be23104f824e6755ecc8d3a34d94 (diff)
parentf54a8880d78f4b0b37371b0b295b2b1e73c8b67f (diff)
Merge branch 'master' into schema-alteration
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_scripts/tests.py6
-rw-r--r--tests/admin_views/tests.py16
-rw-r--r--tests/backends/tests.py9
-rw-r--r--tests/file_storage/tests.py20
-rw-r--r--tests/generic_relations/models.py4
-rw-r--r--tests/generic_relations/tests.py7
-rw-r--r--tests/generic_views/tests.py11
-rw-r--r--tests/i18n/tests.py6
-rw-r--r--tests/model_fields/models.py17
-rw-r--r--tests/model_fields/test_imagefield.py8
-rw-r--r--tests/model_fields/tests.py5
-rw-r--r--tests/model_forms/models.py12
-rwxr-xr-xtests/runtests.py94
-rw-r--r--tests/serializers_regress/models.py2
-rw-r--r--tests/template_tests/tests.py9
-rw-r--r--tests/test_discovery_sample/__init__.py (renamed from tests/test_runner/deprecation_app/__init__.py)0
-rw-r--r--tests/test_discovery_sample/pattern_tests.py7
-rw-r--r--tests/test_discovery_sample/tests/__init__.py (renamed from tests/test_runner/invalid_app/models/__init__.py)0
-rw-r--r--tests/test_discovery_sample/tests/tests.py7
-rw-r--r--tests/test_discovery_sample/tests_sample.py22
-rw-r--r--tests/test_discovery_sample2/__init__.py0
-rw-r--r--tests/test_discovery_sample2/tests.py7
-rw-r--r--tests/test_runner/test_discover_runner.py68
-rw-r--r--tests/test_runner/tests.py25
-rw-r--r--tests/test_runner_deprecation_app/__init__.py0
-rw-r--r--tests/test_runner_deprecation_app/models.py (renamed from tests/test_runner/deprecation_app/models.py)0
-rw-r--r--tests/test_runner_deprecation_app/tests.py (renamed from tests/test_runner/deprecation_app/tests.py)2
-rw-r--r--tests/test_runner_invalid_app/__init__.py (renamed from tests/test_runner/invalid_app/__init__.py)0
-rw-r--r--tests/test_runner_invalid_app/models/__init__.py0
-rw-r--r--tests/test_runner_invalid_app/tests/__init__.py (renamed from tests/test_runner/invalid_app/tests/__init__.py)0
-rw-r--r--tests/utils_tests/tests.py34
-rw-r--r--tests/validation/tests.py6
32 files changed, 237 insertions, 167 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 5071977b2d..c8986770f3 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -19,9 +19,9 @@ from django import conf, get_version
from django.conf import settings
from django.core.management import BaseCommand, CommandError
from django.db import connection
-from django.test.simple import DjangoTestSuiteRunner
+from django.test.runner import DiscoverRunner
from django.utils import unittest
-from django.utils.encoding import force_str, force_text
+from django.utils.encoding import force_text
from django.utils._os import upath
from django.utils.six import StringIO
from django.test import LiveServerTestCase
@@ -1090,7 +1090,7 @@ class ManageValidate(AdminScriptTestCase):
self.assertOutput(out, '0 errors found')
-class CustomTestRunner(DjangoTestSuiteRunner):
+class CustomTestRunner(DiscoverRunner):
def __init__(self, *args, **kwargs):
assert 'liveserver' not in kwargs
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index e0000ff6b5..8e678a72b3 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -26,6 +26,7 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
+from django.db import connection
from django.forms.util import ErrorList
from django.template.response import TemplateResponse
from django.test import TestCase
@@ -3605,7 +3606,13 @@ class UserAdminTest(TestCase):
# Don't depend on a warm cache, see #17377.
ContentType.objects.clear_cache()
- with self.assertNumQueries(10):
+
+ expected_queries = 10
+ # Oracle doesn't implement "RELEASE SAVPOINT", see #20387.
+ if connection.vendor == 'oracle':
+ expected_queries -= 1
+
+ with self.assertNumQueries(expected_queries):
response = self.client.get('/test_admin/admin/auth/user/%s/' % u.pk)
self.assertEqual(response.status_code, 200)
@@ -3643,7 +3650,12 @@ class GroupAdminTest(TestCase):
def test_group_permission_performance(self):
g = Group.objects.create(name="test_group")
- with self.assertNumQueries(8): # instead of 259!
+ expected_queries = 8
+ # Oracle doesn't implement "RELEASE SAVPOINT", see #20387.
+ if connection.vendor == 'oracle':
+ expected_queries -= 1
+
+ with self.assertNumQueries(expected_queries):
response = self.client.get('/test_admin/admin/auth/group/%s/' % g.pk)
self.assertEqual(response.status_code, 200)
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index a426926cef..81b2851403 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -367,14 +367,19 @@ class EscapingChecks(TestCase):
All tests in this test case are also run with settings.DEBUG=True in
EscapingChecksDebug test case, to also test CursorDebugWrapper.
"""
+
+ # For Oracle, when you want to select a value, you need to specify the
+ # special pseudo-table 'dual'; a select with no from clause is invalid.
+ bare_select_suffix = " FROM DUAL" if connection.vendor == 'oracle' else ""
+
def test_paramless_no_escaping(self):
cursor = connection.cursor()
- cursor.execute("SELECT '%s'")
+ cursor.execute("SELECT '%s'" + self.bare_select_suffix)
self.assertEqual(cursor.fetchall()[0][0], '%s')
def test_parameter_escaping(self):
cursor = connection.cursor()
- cursor.execute("SELECT '%%', %s", ('%d',))
+ cursor.execute("SELECT '%%', %s" + self.bare_select_suffix, ('%d',))
self.assertEqual(cursor.fetchall()[0], ('%', '%d'))
@unittest.skipUnless(connection.vendor == 'sqlite',
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 5e6adee894..e4b71dba82 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -29,16 +29,10 @@ from django.utils._os import upath
from django.test.utils import override_settings
from servers.tests import LiveServerBase
-# Try to import PIL in either of the two ways it can end up installed.
-# Checking for the existence of Image is enough for CPython, but
-# for PyPy, you need to check for the underlying modules
try:
- from PIL import Image, _imaging
-except ImportError:
- try:
- import Image, _imaging
- except ImportError:
- Image = None
+ from django.utils.image import Image
+except ImproperlyConfigured:
+ Image = None
class GetStorageClassTests(SimpleTestCase):
@@ -494,7 +488,7 @@ class DimensionClosingBug(unittest.TestCase):
"""
Test that get_image_dimensions() properly closes files (#8817)
"""
- @unittest.skipUnless(Image, "PIL not installed")
+ @unittest.skipUnless(Image, "Pillow/PIL not installed")
def test_not_closing_of_files(self):
"""
Open files passed into get_image_dimensions() should stay opened.
@@ -505,7 +499,7 @@ class DimensionClosingBug(unittest.TestCase):
finally:
self.assertTrue(not empty_io.closed)
- @unittest.skipUnless(Image, "PIL not installed")
+ @unittest.skipUnless(Image, "Pillow/PIL not installed")
def test_closing_of_filenames(self):
"""
get_image_dimensions() called with a filename should closed the file.
@@ -542,7 +536,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
Test that get_image_dimensions() works properly after various calls
using a file handler (#11158)
"""
- @unittest.skipUnless(Image, "PIL not installed")
+ @unittest.skipUnless(Image, "Pillow/PIL not installed")
def test_multiple_calls(self):
"""
Multiple calls of get_image_dimensions() should return the same size.
@@ -556,7 +550,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
self.assertEqual(image_pil.size, size_1)
self.assertEqual(size_1, size_2)
- @unittest.skipUnless(Image, "PIL not installed")
+ @unittest.skipUnless(Image, "Pillow/PIL not installed")
def test_bug_19457(self):
"""
Regression test for #19457
diff --git a/tests/generic_relations/models.py b/tests/generic_relations/models.py
index 34dc8d3a7d..2acb982b9a 100644
--- a/tests/generic_relations/models.py
+++ b/tests/generic_relations/models.py
@@ -98,3 +98,7 @@ class Gecko(models.Model):
# To test fix for #11263
class Rock(Mineral):
tags = generic.GenericRelation(TaggedItem)
+
+class ManualPK(models.Model):
+ id = models.IntegerField(primary_key=True)
+ tags = generic.GenericRelation(TaggedItem)
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py
index dd9dc506ca..79c7bc6184 100644
--- a/tests/generic_relations/tests.py
+++ b/tests/generic_relations/tests.py
@@ -6,7 +6,7 @@ from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal,
- Vegetable, Mineral, Gecko, Rock)
+ Vegetable, Mineral, Gecko, Rock, ManualPK)
class GenericRelationsTests(TestCase):
@@ -75,12 +75,17 @@ class GenericRelationsTests(TestCase):
"<Animal: Lion>",
"<Animal: Platypus>"
])
+ # Create another fatty tagged instance with different PK to ensure
+ # there is a content type restriction in the generated queries below.
+ mpk = ManualPK.objects.create(id=lion.pk)
+ mpk.tags.create(tag="fatty")
self.assertQuerysetEqual(Animal.objects.filter(tags__tag='fatty'), [
"<Animal: Platypus>"
])
self.assertQuerysetEqual(Animal.objects.exclude(tags__tag='fatty'), [
"<Animal: Lion>"
])
+ mpk.delete()
# If you delete an object with an explicit Generic relation, the related
# objects are deleted when the source object is deleted.
diff --git a/tests/generic_views/tests.py b/tests/generic_views/tests.py
deleted file mode 100644
index 244aa3c701..0000000000
--- a/tests/generic_views/tests.py
+++ /dev/null
@@ -1,11 +0,0 @@
-from __future__ import absolute_import
-
-from .test_base import (ViewTest, TemplateViewTest, RedirectViewTest,
- GetContextDataTest)
-from .test_dates import (ArchiveIndexViewTests, YearArchiveViewTests,
- MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests,
- DateDetailViewTests)
-from .test_detail import DetailViewTest
-from .test_edit import (FormMixinTests, BasicFormTests, ModelFormMixinTests,
- CreateViewTests, UpdateViewTests, DeleteViewTests)
-from .test_list import ListViewTests
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index d26a201efa..1022c8d2f1 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -43,14 +43,8 @@ if can_run_compilation_tests:
from .commands.compilation import (PoFileTests, PoFileContentsTests,
PercentRenderingTests, MultipleLocaleCompilationTests,
CompilationErrorHandling)
-from .contenttypes.tests import ContentTypeTests
from .forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
from .models import Company, TestModel
-from .patterns.tests import (URLRedirectWithoutTrailingSlashTests,
- URLTranslationTests, URLDisabledTests, URLTagTests, URLTestCaseBase,
- URLRedirectWithoutTrailingSlashSettingTests, URLNamespaceTests,
- URLPrefixTests, URLResponseTests, URLRedirectTests, PathUnusedTests,
- URLVaryAcceptLanguageTests)
here = os.path.dirname(os.path.abspath(upath(__file__)))
diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py
index c3b2f7fccb..2d602d6412 100644
--- a/tests/model_fields/models.py
+++ b/tests/model_fields/models.py
@@ -1,17 +1,12 @@
import os
import tempfile
-# Try to import PIL in either of the two ways it can end up installed.
-# Checking for the existence of Image is enough for CPython, but for PyPy,
-# you need to check for the underlying modules.
+from django.core.exceptions import ImproperlyConfigured
try:
- from PIL import Image, _imaging
-except ImportError:
- try:
- import Image, _imaging
- except ImportError:
- Image = None
+ from django.utils.image import Image
+except ImproperlyConfigured:
+ Image = None
from django.core.files.storage import FileSystemStorage
from django.db import models
@@ -87,7 +82,7 @@ class VerboseNameField(models.Model):
field9 = models.FileField("verbose field9", upload_to="unused")
field10 = models.FilePathField("verbose field10")
field11 = models.FloatField("verbose field11")
- # Don't want to depend on PIL in this test
+ # Don't want to depend on Pillow/PIL in this test
#field_image = models.ImageField("verbose field")
field12 = models.IntegerField("verbose field12")
field13 = models.IPAddressField("verbose field13")
@@ -119,7 +114,7 @@ class Document(models.Model):
###############################################################################
# ImageField
-# If PIL available, do these tests.
+# If Pillow/PIL available, do these tests.
if Image:
class TestImageFieldFile(ImageFieldFile):
"""
diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py
index df0215db3d..457892ddb8 100644
--- a/tests/model_fields/test_imagefield.py
+++ b/tests/model_fields/test_imagefield.py
@@ -3,20 +3,24 @@ from __future__ import absolute_import
import os
import shutil
+from django.core.exceptions import ImproperlyConfigured
from django.core.files import File
from django.core.files.images import ImageFile
from django.test import TestCase
from django.utils._os import upath
from django.utils.unittest import skipIf
-from .models import Image
+try:
+ from .models import Image
+except ImproperlyConfigured:
+ Image = None
if Image:
from .models import (Person, PersonWithHeight, PersonWithHeightAndWidth,
PersonDimensionsFirst, PersonTwoImages, TestImageFieldFile)
from .models import temp_storage_dir
else:
- # PIL not available, create dummy classes (tests will be skipped anyway)
+ # Pillow not available, create dummy classes (tests will be skipped anyway)
class Person():
pass
PersonWithHeight = PersonWithHeightAndWidth = PersonDimensionsFirst = Person
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index 035a5c2ae3..e1e38d0ec7 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -15,11 +15,6 @@ from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post,
NullBooleanModel, BooleanModel, DataModel, Document, RenamedField,
VerboseNameField, FksToBooleans)
-from .test_imagefield import (ImageFieldTests, ImageFieldTwoDimensionsTests,
- TwoImageFieldTests, ImageFieldNoDimensionsTests,
- ImageFieldOneDimensionTests, ImageFieldDimensionsFirstTests,
- ImageFieldUsingFileTests)
-
class BasicFieldTests(test.TestCase):
def test_show_hidden_initial(self):
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py
index 25c780f1c2..a79d9b8c5b 100644
--- a/tests/model_forms/models.py
+++ b/tests/model_forms/models.py
@@ -11,6 +11,7 @@ from __future__ import unicode_literals
import os
import tempfile
+from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.utils import six
@@ -91,14 +92,7 @@ class TextFile(models.Model):
return self.description
try:
- # If PIL is available, try testing ImageFields. Checking for the existence
- # of Image is enough for CPython, but for PyPy, you need to check for the
- # underlying modules If PIL is not available, ImageField tests are omitted.
- # Try to import PIL in either of the two ways it can end up installed.
- try:
- from PIL import Image, _imaging
- except ImportError:
- import Image, _imaging
+ from django.utils.image import Image
test_images = True
@@ -137,7 +131,7 @@ try:
def __str__(self):
return self.description
-except ImportError:
+except ImproperlyConfigured:
test_images = False
@python_2_unicode_compatible
diff --git a/tests/runtests.py b/tests/runtests.py
index ee2488c4a1..a18324f676 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -10,16 +10,23 @@ from django import contrib
from django.utils._os import upath
from django.utils import six
-CONTRIB_DIR_NAME = 'django.contrib'
+CONTRIB_MODULE_PATH = 'django.contrib'
TEST_TEMPLATE_DIR = 'templates'
RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
+
TEMP_DIR = tempfile.mkdtemp(prefix='django_')
os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR
-SUBDIRS_TO_SKIP = ['templates']
+SUBDIRS_TO_SKIP = [
+ 'templates',
+ 'test_discovery_sample',
+ 'test_discovery_sample2',
+ 'test_runner_deprecation_app',
+ 'test_runner_invalid_app',
+]
ALWAYS_INSTALLED_APPS = [
'shared_models',
@@ -40,17 +47,12 @@ ALWAYS_INSTALLED_APPS = [
'staticfiles_tests.apps.no_label',
]
-def geodjango(settings):
- # All databases must have spatial backends to run GeoDjango tests.
- spatial_dbs = [name for name, db_dict in settings.DATABASES.items()
- if db_dict['ENGINE'].startswith('django.contrib.gis')]
- return len(spatial_dbs) == len(settings.DATABASES)
def get_test_modules():
modules = []
- for loc, dirpath in (
+ for modpath, dirpath in (
(None, RUNTESTS_DIR),
- (CONTRIB_DIR_NAME, CONTRIB_DIR)):
+ (CONTRIB_MODULE_PATH, CONTRIB_DIR)):
for f in os.listdir(dirpath):
if ('.' in f or
# Python 3 byte code dirs (PEP 3147)
@@ -59,9 +61,14 @@ def get_test_modules():
os.path.basename(f) in SUBDIRS_TO_SKIP or
os.path.isfile(f)):
continue
- modules.append((loc, f))
+ modules.append((modpath, f))
return modules
+def get_installed():
+ from django.db.models.loading import get_apps
+ return [app.__name__.rsplit('.', 1)[0] for app in get_apps()]
+
+
def setup(verbosity, test_labels):
from django.conf import settings
from django.db.models.loading import get_apps, load_app
@@ -95,25 +102,45 @@ def setup(verbosity, test_labels):
get_apps()
# Load all the test model apps.
- test_labels_set = set([label.split('.')[0] for label in test_labels])
test_modules = get_test_modules()
+ # Reduce given test labels to just the app module path
+ test_labels_set = set()
+ for label in test_labels:
+ bits = label.split('.')
+ if bits[:2] == ['django', 'contrib']:
+ bits = bits[:3]
+ else:
+ bits = bits[:1]
+ test_labels_set.add('.'.join(bits))
+
# If GeoDjango, then we'll want to add in the test applications
# that are a part of its test suite.
- if geodjango(settings):
+ from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
+ if HAS_SPATIAL_DB:
from django.contrib.gis.tests import geo_apps
- test_modules.extend(geo_apps(runtests=True))
+ test_modules.extend(geo_apps())
settings.INSTALLED_APPS.extend(['django.contrib.gis', 'django.contrib.sitemaps'])
- for module_dir, module_name in test_modules:
- if module_dir:
- module_label = '.'.join([module_dir, module_name])
+ for modpath, module_name in test_modules:
+ if modpath:
+ module_label = '.'.join([modpath, module_name])
else:
module_label = module_name
- # if the module was named on the command line, or
+ # if the module (or an ancestor) was named on the command line, or
# no modules were named (i.e., run all), import
- # this module and add it to the list to test.
- if not test_labels or module_name in test_labels_set:
+ # this module and add it to INSTALLED_APPS.
+ if not test_labels:
+ module_found_in_labels = True
+ else:
+ match = lambda label: (
+ module_label == label or # exact match
+ module_label.startswith(label + '.') # ancestor match
+ )
+
+ module_found_in_labels = any(match(l) for l in test_labels_set)
+
+ if module_found_in_labels:
if verbosity >= 2:
print("Importing application %s" % module_name)
mod = load_app(module_label)
@@ -139,21 +166,19 @@ def django_tests(verbosity, interactive, failfast, test_labels):
state = setup(verbosity, test_labels)
extra_tests = []
- # If GeoDjango is used, add it's tests that aren't a part of
- # an application (e.g., GEOS, GDAL, Distance objects).
- if geodjango(settings) and (not test_labels or 'gis' in test_labels):
- from django.contrib.gis.tests import geodjango_suite
- extra_tests.append(geodjango_suite(apps=False))
-
# Run the test suite, including the extra validation tests.
from django.test.utils import get_runner
if not hasattr(settings, 'TEST_RUNNER'):
- settings.TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'
+ settings.TEST_RUNNER = 'django.test.runner.DiscoverRunner'
TestRunner = get_runner(settings)
- test_runner = TestRunner(verbosity=verbosity, interactive=interactive,
- failfast=failfast)
- failures = test_runner.run_tests(test_labels, extra_tests=extra_tests)
+ test_runner = TestRunner(
+ verbosity=verbosity,
+ interactive=interactive,
+ failfast=failfast,
+ )
+ failures = test_runner.run_tests(
+ test_labels or get_installed(), extra_tests=extra_tests)
teardown(state)
return failures
@@ -162,10 +187,7 @@ def django_tests(verbosity, interactive, failfast, test_labels):
def bisect_tests(bisection_label, options, test_labels):
state = setup(int(options.verbosity), test_labels)
- if not test_labels:
- # Get the full list of test labels to use for bisection
- from django.db.models.loading import get_apps
- test_labels = [app.__name__.split('.')[-2] for app in get_apps()]
+ test_labels = test_labels or get_installed()
print('***** Bisecting test suite: %s' % ' '.join(test_labels))
@@ -222,11 +244,7 @@ def bisect_tests(bisection_label, options, test_labels):
def paired_tests(paired_test, options, test_labels):
state = setup(int(options.verbosity), test_labels)
- if not test_labels:
- print("")
- # Get the full list of test labels to use for bisection
- from django.db.models.loading import get_apps
- test_labels = [app.__name__.split('.')[-2] for app in get_apps()]
+ test_labels = test_labels or get_installed()
print('***** Trying paired execution')
diff --git a/tests/serializers_regress/models.py b/tests/serializers_regress/models.py
index 21fe073122..21a3448a8e 100644
--- a/tests/serializers_regress/models.py
+++ b/tests/serializers_regress/models.py
@@ -2,7 +2,7 @@
A test spanning all the capabilities of all the serializers.
This class sets up a model for each model field type
-(except for image types, because of the PIL dependency).
+(except for image types, because of the Pillow/PIL dependency).
"""
from django.db import models
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index da1562d2d5..2aeaee9464 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -36,15 +36,6 @@ from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.tzinfo import LocalTimezone
-from .test_callables import CallableVariablesTests
-from .test_context import ContextTests
-from .test_custom import CustomTagTests, CustomFilterTests
-from .test_parser import ParserTests
-from .test_unicode import UnicodeTests
-from .test_nodelist import NodelistTest, ErrorIndexTest
-from .test_smartif import SmartIfTests
-from .test_response import (TemplateResponseTest, CacheMiddlewareTest,
- SimpleTemplateResponseTest, CustomURLConfTest)
try:
from .loaders import RenderToStringTest, EggLoaderTest
diff --git a/tests/test_runner/deprecation_app/__init__.py b/tests/test_discovery_sample/__init__.py
index e69de29bb2..e69de29bb2 100644
--- a/tests/test_runner/deprecation_app/__init__.py
+++ b/tests/test_discovery_sample/__init__.py
diff --git a/tests/test_discovery_sample/pattern_tests.py b/tests/test_discovery_sample/pattern_tests.py
new file mode 100644
index 0000000000..f62a233d75
--- /dev/null
+++ b/tests/test_discovery_sample/pattern_tests.py
@@ -0,0 +1,7 @@
+from unittest import TestCase
+
+
+class Test(TestCase):
+
+ def test_sample(self):
+ self.assertEqual(1, 1)
diff --git a/tests/test_runner/invalid_app/models/__init__.py b/tests/test_discovery_sample/tests/__init__.py
index e69de29bb2..e69de29bb2 100644
--- a/tests/test_runner/invalid_app/models/__init__.py
+++ b/tests/test_discovery_sample/tests/__init__.py
diff --git a/tests/test_discovery_sample/tests/tests.py b/tests/test_discovery_sample/tests/tests.py
new file mode 100644
index 0000000000..58bd4e7f1e
--- /dev/null
+++ b/tests/test_discovery_sample/tests/tests.py
@@ -0,0 +1,7 @@
+from unittest import TestCase
+
+
+class Test(TestCase):
+
+ def test_sample(self):
+ pass
diff --git a/tests/test_discovery_sample/tests_sample.py b/tests/test_discovery_sample/tests_sample.py
new file mode 100644
index 0000000000..c541bc4cd6
--- /dev/null
+++ b/tests/test_discovery_sample/tests_sample.py
@@ -0,0 +1,22 @@
+from unittest import TestCase as UnitTestCase
+
+from django.test import TestCase as DjangoTestCase
+from django.utils.unittest import TestCase as UT2TestCase
+
+
+class TestVanillaUnittest(UnitTestCase):
+
+ def test_sample(self):
+ self.assertEqual(1, 1)
+
+
+class TestUnittest2(UT2TestCase):
+
+ def test_sample(self):
+ self.assertEqual(1, 1)
+
+
+class TestDjangoTestCase(DjangoTestCase):
+
+ def test_sample(self):
+ self.assertEqual(1, 1)
diff --git a/tests/test_discovery_sample2/__init__.py b/tests/test_discovery_sample2/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/test_discovery_sample2/__init__.py
diff --git a/tests/test_discovery_sample2/tests.py b/tests/test_discovery_sample2/tests.py
new file mode 100644
index 0000000000..232054a9f1
--- /dev/null
+++ b/tests/test_discovery_sample2/tests.py
@@ -0,0 +1,7 @@
+from django.test import TestCase
+
+
+class Test(TestCase):
+
+ def test_sample(self):
+ pass
diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py
new file mode 100644
index 0000000000..3dc364b351
--- /dev/null
+++ b/tests/test_runner/test_discover_runner.py
@@ -0,0 +1,68 @@
+from django.test import TestCase
+from django.test.runner import DiscoverRunner
+
+
+class DiscoverRunnerTest(TestCase):
+
+ def test_dotted_test_module(self):
+ count = DiscoverRunner().build_suite(
+ ["test_discovery_sample.tests_sample"],
+ ).countTestCases()
+
+ self.assertEqual(count, 3)
+
+ def test_dotted_test_class_vanilla_unittest(self):
+ count = DiscoverRunner().build_suite(
+ ["test_discovery_sample.tests_sample.TestVanillaUnittest"],
+ ).countTestCases()
+
+ self.assertEqual(count, 1)
+
+ def test_dotted_test_class_unittest2(self):
+ count = DiscoverRunner().build_suite(
+ ["test_discovery_sample.tests_sample.TestUnittest2"],
+ ).countTestCases()
+
+ self.assertEqual(count, 1)
+
+ def test_dotted_test_class_django_testcase(self):
+ count = DiscoverRunner().build_suite(
+ ["test_discovery_sample.tests_sample.TestDjangoTestCase"],
+ ).countTestCases()
+
+ self.assertEqual(count, 1)
+
+ def test_dotted_test_method_vanilla_unittest(self):
+ count = DiscoverRunner().build_suite(
+ ["test_discovery_sample.tests_sample.TestVanillaUnittest.test_sample"],
+ ).countTestCases()
+
+ self.assertEqual(count, 1)
+
+ def test_dotted_test_method_unittest2(self):
+ count = DiscoverRunner().build_suite(
+ ["test_discovery_sample.tests_sample.TestUnittest2.test_sample"],
+ ).countTestCases()
+
+ self.assertEqual(count, 1)
+
+ def test_dotted_test_method_django_testcase(self):
+ count = DiscoverRunner().build_suite(
+ ["test_discovery_sample.tests_sample.TestDjangoTestCase.test_sample"],
+ ).countTestCases()
+
+ self.assertEqual(count, 1)
+
+ def test_pattern(self):
+ count = DiscoverRunner(
+ pattern="*_tests.py",
+ ).build_suite(["test_discovery_sample"]).countTestCases()
+
+ self.assertEqual(count, 1)
+
+ def test_file_path(self):
+ count = DiscoverRunner().build_suite(
+ ["test_discovery_sample/"],
+ ).countTestCases()
+
+ self.assertEqual(count, 4)
diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py
index 9f0cc794b7..95ccf0242a 100644
--- a/tests/test_runner/tests.py
+++ b/tests/test_runner/tests.py
@@ -9,7 +9,7 @@ from optparse import make_option
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django import db
-from django.test import simple, TransactionTestCase, skipUnlessDBFeature
+from django.test import runner, TransactionTestCase, skipUnlessDBFeature
from django.test.simple import DjangoTestSuiteRunner, get_tests
from django.test.testcases import connections_support_transactions
from django.utils import unittest
@@ -20,7 +20,7 @@ from .models import Person
TEST_APP_OK = 'test_runner.valid_app.models'
-TEST_APP_ERROR = 'test_runner.invalid_app.models'
+TEST_APP_ERROR = 'test_runner_invalid_app.models'
class DependencyOrderingTests(unittest.TestCase):
@@ -36,7 +36,7 @@ class DependencyOrderingTests(unittest.TestCase):
'bravo': ['charlie'],
}
- ordered = simple.dependency_ordered(raw, dependencies=dependencies)
+ ordered = runner.dependency_ordered(raw, dependencies=dependencies)
ordered_sigs = [sig for sig,value in ordered]
self.assertIn('s1', ordered_sigs)
@@ -56,7 +56,7 @@ class DependencyOrderingTests(unittest.TestCase):
'bravo': ['charlie'],
}
- ordered = simple.dependency_ordered(raw, dependencies=dependencies)
+ ordered = runner.dependency_ordered(raw, dependencies=dependencies)
ordered_sigs = [sig for sig,value in ordered]
self.assertIn('s1', ordered_sigs)
@@ -83,7 +83,7 @@ class DependencyOrderingTests(unittest.TestCase):
'delta': ['charlie'],
}
- ordered = simple.dependency_ordered(raw, dependencies=dependencies)
+ ordered = runner.dependency_ordered(raw, dependencies=dependencies)
ordered_sigs = [sig for sig,aliases in ordered]
self.assertIn('s1', ordered_sigs)
@@ -110,7 +110,7 @@ class DependencyOrderingTests(unittest.TestCase):
'alpha': ['bravo'],
}
- self.assertRaises(ImproperlyConfigured, simple.dependency_ordered, raw, dependencies=dependencies)
+ self.assertRaises(ImproperlyConfigured, runner.dependency_ordered, raw, dependencies=dependencies)
def test_own_alias_dependency(self):
raw = [
@@ -121,7 +121,7 @@ class DependencyOrderingTests(unittest.TestCase):
}
with self.assertRaises(ImproperlyConfigured):
- simple.dependency_ordered(raw, dependencies=dependencies)
+ runner.dependency_ordered(raw, dependencies=dependencies)
# reordering aliases shouldn't matter
raw = [
@@ -129,7 +129,7 @@ class DependencyOrderingTests(unittest.TestCase):
]
with self.assertRaises(ImproperlyConfigured):
- simple.dependency_ordered(raw, dependencies=dependencies)
+ runner.dependency_ordered(raw, dependencies=dependencies)
class MockTestRunner(object):
@@ -156,7 +156,7 @@ class ManageCommandTests(unittest.TestCase):
testrunner='test_runner.NonExistentRunner')
-class CustomOptionsTestRunner(simple.DjangoTestSuiteRunner):
+class CustomOptionsTestRunner(runner.DiscoverRunner):
option_list = (
make_option('--option_a','-a', action='store', dest='option_a', default='1'),
make_option('--option_b','-b', action='store', dest='option_b', default='2'),
@@ -289,15 +289,16 @@ class DummyBackendTest(unittest.TestCase):
class DeprecationDisplayTest(AdminScriptTestCase):
# tests for 19546
def setUp(self):
- settings = {'INSTALLED_APPS': '("test_runner.deprecation_app",)',
- 'DATABASES': '{"default": {"ENGINE":"django.db.backends.sqlite3", "NAME":":memory:"}}' }
+ settings = {
+ 'DATABASES': '{"default": {"ENGINE":"django.db.backends.sqlite3", "NAME":":memory:"}}'
+ }
self.write_settings('settings.py', sdict=settings)
def tearDown(self):
self.remove_settings('settings.py')
def test_runner_deprecation_verbosity_default(self):
- args = ['test', '--settings=test_project.settings']
+ args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app']
out, err = self.run_django_admin(args)
self.assertIn("DeprecationWarning: warning from test", err)
self.assertIn("DeprecationWarning: module-level warning from deprecation_app", err)
diff --git a/tests/test_runner_deprecation_app/__init__.py b/tests/test_runner_deprecation_app/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/test_runner_deprecation_app/__init__.py
diff --git a/tests/test_runner/deprecation_app/models.py b/tests/test_runner_deprecation_app/models.py
index 71a8362390..71a8362390 100644
--- a/tests/test_runner/deprecation_app/models.py
+++ b/tests/test_runner_deprecation_app/models.py
diff --git a/tests/test_runner/deprecation_app/tests.py b/tests/test_runner_deprecation_app/tests.py
index 6dee0888ec..24d716f2bb 100644
--- a/tests/test_runner/deprecation_app/tests.py
+++ b/tests/test_runner_deprecation_app/tests.py
@@ -7,5 +7,3 @@ warnings.warn("module-level warning from deprecation_app", DeprecationWarning)
class DummyTest(TestCase):
def test_warn(self):
warnings.warn("warning from test", DeprecationWarning)
-
-
diff --git a/tests/test_runner/invalid_app/__init__.py b/tests/test_runner_invalid_app/__init__.py
index 45efd37d3e..45efd37d3e 100644
--- a/tests/test_runner/invalid_app/__init__.py
+++ b/tests/test_runner_invalid_app/__init__.py
diff --git a/tests/test_runner_invalid_app/models/__init__.py b/tests/test_runner_invalid_app/models/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/test_runner_invalid_app/models/__init__.py
diff --git a/tests/test_runner/invalid_app/tests/__init__.py b/tests/test_runner_invalid_app/tests/__init__.py
index b4ed71824b..b4ed71824b 100644
--- a/tests/test_runner/invalid_app/tests/__init__.py
+++ b/tests/test_runner_invalid_app/tests/__init__.py
diff --git a/tests/utils_tests/tests.py b/tests/utils_tests/tests.py
deleted file mode 100644
index 8d7fda4800..0000000000
--- a/tests/utils_tests/tests.py
+++ /dev/null
@@ -1,34 +0,0 @@
-"""
-Tests for django.utils.
-"""
-from __future__ import absolute_import
-
-from .test_archive import TestBzip2Tar, TestGzipTar, TestTar, TestZip
-from .test_baseconv import TestBaseConv
-from .test_checksums import TestUtilsChecksums
-from .test_crypto import TestUtilsCryptoMisc, TestUtilsCryptoPBKDF2
-from .test_datastructures import (DictWrapperTests, ImmutableListTests,
- MergeDictTests, MultiValueDictTests, SortedDictTests)
-from .test_dateformat import DateFormatTests
-from .test_dateparse import DateParseTests
-from .test_datetime_safe import DatetimeTests
-from .test_decorators import DecoratorFromMiddlewareTests
-from .test_encoding import TestEncodingUtils
-from .test_feedgenerator import FeedgeneratorTest
-from .test_functional import FunctionalTestCase
-from .test_html import TestUtilsHtml
-from .test_http import TestUtilsHttp, ETagProcessingTests, HttpDateProcessingTests
-from .test_itercompat import TestIsIterator
-from .test_ipv6 import TestUtilsIPv6
-from .test_jslex import JsToCForGettextTest, JsTokensTest
-from .test_module_loading import (CustomLoader, DefaultLoader, EggLoader,
- ModuleImportTestCase)
-from .test_numberformat import TestNumberFormat
-from .test_os_utils import SafeJoinTests
-from .test_regex_helper import NormalizeTests
-from .test_simplelazyobject import TestUtilsSimpleLazyObject
-from .test_termcolors import TermColorTests
-from .test_text import TestUtilsText
-from .test_timesince import TimesinceTests
-from .test_timezone import TimezoneTests
-from .test_tzinfo import TzinfoTests
diff --git a/tests/validation/tests.py b/tests/validation/tests.py
index ead1b57981..b571e0c298 100644
--- a/tests/validation/tests.py
+++ b/tests/validation/tests.py
@@ -8,12 +8,6 @@ from . import ValidationTestCase
from .models import (Author, Article, ModelToValidate,
GenericIPAddressTestModel, GenericIPAddrUnpackUniqueTest)
-# Import other tests for this package.
-from .test_custom_messages import CustomMessagesTest
-from .test_error_messages import ValidationMessagesTest
-from .test_unique import GetUniqueCheckTests, PerformUniqueChecksTest
-from .test_validators import TestModelsWithValidators
-
class BaseModelValidationTests(ValidationTestCase):