diff options
| author | Kevin Kubasik <kevin@kubasik.net> | 2009-07-01 14:24:25 +0000 |
|---|---|---|
| committer | Kevin Kubasik <kevin@kubasik.net> | 2009-07-01 14:24:25 +0000 |
| commit | f2be59849c6e6adc654edd7ea27890c1719738cb (patch) | |
| tree | 776cff91ed7aefe21b6f4f69d7e20115d8e19867 /docs | |
| parent | 8cd4df145f7ae244c9ff70dfc92ec9d169ef39e5 (diff) | |
[gsoc2009-testing] Added support for skipping tests that cannot pass. Add auth to regression suite urls.py so reverse() works.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/test-improvements@11142 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/testing.txt | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt index d4e1eb8eaf..d1a40d74c2 100644 --- a/docs/topics/testing.txt +++ b/docs/topics/testing.txt @@ -1045,6 +1045,58 @@ For example:: This test case will load the contents of ``myapp.test_models`` and add any subclass of ``django.db.models.Model`` to ``myapp.models``. +Skipping tests bound to fail +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded: 1.1 + +Occasionally it's helpful to specify tests that are skipped under certain +circumstances. To accomplish this, the Django test framework offers decorators +that you can apply to your test methods for them to be conditionally skipped. + +You can supply your own condition function as follows:: + + from django.tests.decorators import * + + class TestUnderCondition(TestCase): + + def _my_condition(): + # Condition returning True if test should be run and False if it + # should be skipped. + + @conditional_skip(_my_condition, reason='This test should be skipped sometimes') + def testOnlyOnTuesday(self): + # Test to run if _my_condition evaluates to True + +In addition, the Django test framework supplies a handful of skip conditions that +handle commonly used conditions for skipping tests. + +``views_required(required_views=[])`` + Does a ``urlresolver.Reverse`` on the required views supplied. Runs test only if + all views in ``required_views`` are in use. + +``modules_required(required_modules=[])`` + Runs tests only if all modules in ``required_modules`` can be imported. + +``skip_specific_database(database_engine)`` + Skips test if ``settings.DATABASE_ENGINE`` is equal to database_engine. + +If a test is skipped, it is added to a skipped category in the test runner and +the test results are reported as such:: + + ====================================================================== + SKIPPED: test_email_found (django.contrib.auth.tests.basic.PasswordResetTest) + ---------------------------------------------------------------------- + Traceback (most recent call last): + File "/Users/dnaquin/Dropbox/Sandbox/django/django/test/decorators.py", line 43, in _skip + raise SkippedTest(reason=reason) + SkippedTest: Required view for this test not found: django.contrib.auth.views.password_reset + + ---------------------------------------------------------------------- + Ran 408 tests in 339.663s + + FAILED (failures=1, skipped=2) + .. _emptying-test-outbox: Emptying the test outbox |
