Code

Ticket #3051: 3051_testing.diff

File 3051_testing.diff, 976 bytes (added by danielr, 4 years ago)

Better patch with more explanation and links to reference.

Line 
1Index: docs/topics/testing.txt
2===================================================================
3--- docs/topics/testing.txt     (revision 13596)
4+++ docs/topics/testing.txt     (working copy)
5@@ -311,6 +311,22 @@
6 but not gracefully. No details of the tests run before the interruption will
7 be reported, and any test databases created by the run will not be destroyed.
8 
9+
10+Using tests outside the test runner
11+-----------------------------------
12+
13+If you want to run tests outside of ``./manage.py test`` - for example in your
14+views, or in the shell - you will need to set up the test environment first.
15+You can do this by running :meth:`django.test.utils.setup_test_environment`::
16+
17+
18+    >>> from django.test.utils import setup_test_environment
19+    >>> setup_test_environment()
20+
21+Note that this is done for you automatically by `./manage.py test`, and is only
22+needed if you're not using running your tests via that command.
23+
24+
25 The test database
26 -----------------
27