diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-06-12 12:34:10 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-06-12 12:34:10 +0000 |
| commit | f0adae4c6e857cabdff790d20dff815a37645d6f (patch) | |
| tree | 6e9aa5476e833585576feef3b99941b9eccd661c /tests | |
| parent | 0686b0662a459150d61fff5bbbba06324a81b9aa (diff) | |
Fixed #12658 -- Fixed test discovery so ImportErrors aren't ignored when both `tests` and `models` are packages. Thanks schinckel for the report and boxm for a patch for the issue.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16382 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
7 files changed, 31 insertions, 0 deletions
diff --git a/tests/regressiontests/test_runner/invalid_app/__init__.py b/tests/regressiontests/test_runner/invalid_app/__init__.py new file mode 100644 index 0000000000..45efd37d3e --- /dev/null +++ b/tests/regressiontests/test_runner/invalid_app/__init__.py @@ -0,0 +1,4 @@ +# Example of app layout that causes issue #12658: +# * Both `models` and `tests` are packages. +# * The tests raise a ImportError exception. +# `test_runner` tests performs test discovery on this app. diff --git a/tests/regressiontests/test_runner/invalid_app/models/__init__.py b/tests/regressiontests/test_runner/invalid_app/models/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/regressiontests/test_runner/invalid_app/models/__init__.py diff --git a/tests/regressiontests/test_runner/invalid_app/tests/__init__.py b/tests/regressiontests/test_runner/invalid_app/tests/__init__.py new file mode 100644 index 0000000000..b4ed71824b --- /dev/null +++ b/tests/regressiontests/test_runner/invalid_app/tests/__init__.py @@ -0,0 +1,4 @@ +# Tests that raise ImportError should not fail silently. +# This is a support fixture for one test case in test_runner + +raise ImportError diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py index 4261e44d7f..cb4d27a7a1 100644 --- a/tests/regressiontests/test_runner/tests.py +++ b/tests/regressiontests/test_runner/tests.py @@ -8,11 +8,18 @@ import warnings from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command from django.test import simple +from django.test.simple import get_tests from django.test.utils import get_warnings_state, restore_warnings_state from django.utils import unittest +from django.utils.importlib import import_module + from regressiontests.admin_scripts.tests import AdminScriptTestCase +TEST_APP_OK = 'regressiontests.test_runner.valid_app.models' +TEST_APP_ERROR = 'regressiontests.test_runner.invalid_app.models' + + class DjangoTestRunnerTests(unittest.TestCase): def setUp(self): self._warnings_state = get_warnings_state() @@ -203,3 +210,16 @@ class CustomTestRunnerOptionsTests(AdminScriptTestCase): out, err = self.run_django_admin(args) self.assertNoOutput(err) self.assertOutput(out, 'bar:foo:31337') + + +class ModulesTestsPackages(unittest.TestCase): + def test_get_tests(self): + "Check that the get_tests helper function can find tests in a directory" + module = import_module(TEST_APP_OK) + tests = get_tests(module) + self.assertIsInstance(tests, type(module)) + + def test_import_error(self): + "Test for #12658 - Tests with ImportError's shouldn't fail silently" + module = import_module(TEST_APP_ERROR) + self.assertRaises(ImportError, get_tests, module) diff --git a/tests/regressiontests/test_runner/valid_app/__init__.py b/tests/regressiontests/test_runner/valid_app/__init__.py new file mode 100644 index 0000000000..8d60a80c53 --- /dev/null +++ b/tests/regressiontests/test_runner/valid_app/__init__.py @@ -0,0 +1,3 @@ +# Example of app layout to verify that the fix for #12658 doesn't break test +# discovery when both `models` and `tests` are packages. +# `test_runner` tests perform test discovery on this app. diff --git a/tests/regressiontests/test_runner/valid_app/models/__init__.py b/tests/regressiontests/test_runner/valid_app/models/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/regressiontests/test_runner/valid_app/models/__init__.py diff --git a/tests/regressiontests/test_runner/valid_app/tests/__init__.py b/tests/regressiontests/test_runner/valid_app/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/regressiontests/test_runner/valid_app/tests/__init__.py |
