advanced.txt 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. =======================
  2. Advanced testing topics
  3. =======================
  4. The request factory
  5. ===================
  6. .. currentmodule:: django.test
  7. .. class:: RequestFactory
  8. The :class:`~django.test.RequestFactory` shares the same API as
  9. the test client. However, instead of behaving like a browser, the
  10. RequestFactory provides a way to generate a request instance that can
  11. be used as the first argument to any view. This means you can test a
  12. view function the same way as you would test any other function -- as
  13. a black box, with exactly known inputs, testing for specific outputs.
  14. The API for the :class:`~django.test.RequestFactory` is a slightly
  15. restricted subset of the test client API:
  16. * It only has access to the HTTP methods :meth:`~Client.get()`,
  17. :meth:`~Client.post()`, :meth:`~Client.put()`,
  18. :meth:`~Client.delete()`, :meth:`~Client.head()`,
  19. :meth:`~Client.options()`, and :meth:`~Client.trace()`.
  20. * These methods accept all the same arguments *except* for
  21. ``follows``. Since this is just a factory for producing
  22. requests, it's up to you to handle the response.
  23. * It does not support middleware. Session and authentication
  24. attributes must be supplied by the test itself if required
  25. for the view to function properly.
  26. Example
  27. -------
  28. The following is a simple unit test using the request factory::
  29. from django.contrib.auth.models import AnonymousUser, User
  30. from django.test import TestCase, RequestFactory
  31. from .views import my_view
  32. class SimpleTest(TestCase):
  33. def setUp(self):
  34. # Every test needs access to the request factory.
  35. self.factory = RequestFactory()
  36. self.user = User.objects.create_user(
  37. username='jacob', email='jacob@…', password='top_secret')
  38. def test_details(self):
  39. # Create an instance of a GET request.
  40. request = self.factory.get('/customer/details')
  41. # Recall that middleware are not supported. You can simulate a
  42. # logged-in user by setting request.user manually.
  43. request.user = self.user
  44. # Or you can simulate an anonymous user by setting request.user to
  45. # an AnonymousUser instance.
  46. request.user = AnonymousUser()
  47. # Test my_view() as if it were deployed at /customer/details
  48. response = my_view(request)
  49. self.assertEqual(response.status_code, 200)
  50. .. _topics-testing-advanced-multidb:
  51. Tests and multiple databases
  52. ============================
  53. .. _topics-testing-primaryreplica:
  54. Testing primary/replica configurations
  55. --------------------------------------
  56. If you're testing a multiple database configuration with primary/replica
  57. (referred to as master/slave by some databases) replication, this strategy of
  58. creating test databases poses a problem.
  59. When the test databases are created, there won't be any replication,
  60. and as a result, data created on the primary won't be seen on the
  61. replica.
  62. To compensate for this, Django allows you to define that a database is
  63. a *test mirror*. Consider the following (simplified) example database
  64. configuration::
  65. DATABASES = {
  66. 'default': {
  67. 'ENGINE': 'django.db.backends.mysql',
  68. 'NAME': 'myproject',
  69. 'HOST': 'dbprimary',
  70. # ... plus some other settings
  71. },
  72. 'replica': {
  73. 'ENGINE': 'django.db.backends.mysql',
  74. 'NAME': 'myproject',
  75. 'HOST': 'dbreplica',
  76. 'TEST_MIRROR': 'default'
  77. # ... plus some other settings
  78. }
  79. }
  80. In this setup, we have two database servers: ``dbprimary``, described
  81. by the database alias ``default``, and ``dbreplica`` described by the
  82. alias ``replica``. As you might expect, ``dbreplica`` has been configured
  83. by the database administrator as a read replica of ``dbprimary``, so in
  84. normal activity, any write to ``default`` will appear on ``replica``.
  85. If Django created two independent test databases, this would break any
  86. tests that expected replication to occur. However, the ``replica``
  87. database has been configured as a test mirror (using the
  88. :setting:`TEST_MIRROR` setting), indicating that under testing,
  89. ``replica`` should be treated as a mirror of ``default``.
  90. When the test environment is configured, a test version of ``replica``
  91. will *not* be created. Instead the connection to ``replica``
  92. will be redirected to point at ``default``. As a result, writes to
  93. ``default`` will appear on ``replica`` -- but because they are actually
  94. the same database, not because there is data replication between the
  95. two databases.
  96. .. _topics-testing-creation-dependencies:
  97. Controlling creation order for test databases
  98. ---------------------------------------------
  99. By default, Django will assume all databases depend on the ``default``
  100. database and therefore always create the ``default`` database first.
  101. However, no guarantees are made on the creation order of any other
  102. databases in your test setup.
  103. If your database configuration requires a specific creation order, you
  104. can specify the dependencies that exist using the
  105. :setting:`TEST_DEPENDENCIES` setting. Consider the following
  106. (simplified) example database configuration::
  107. DATABASES = {
  108. 'default': {
  109. # ... db settings
  110. 'TEST_DEPENDENCIES': ['diamonds']
  111. },
  112. 'diamonds': {
  113. # ... db settings
  114. 'TEST_DEPENDENCIES': []
  115. },
  116. 'clubs': {
  117. # ... db settings
  118. 'TEST_DEPENDENCIES': ['diamonds']
  119. },
  120. 'spades': {
  121. # ... db settings
  122. 'TEST_DEPENDENCIES': ['diamonds','hearts']
  123. },
  124. 'hearts': {
  125. # ... db settings
  126. 'TEST_DEPENDENCIES': ['diamonds','clubs']
  127. }
  128. }
  129. Under this configuration, the ``diamonds`` database will be created first,
  130. as it is the only database alias without dependencies. The ``default`` and
  131. ``clubs`` alias will be created next (although the order of creation of this
  132. pair is not guaranteed); then ``hearts``; and finally ``spades``.
  133. If there are any circular dependencies in the
  134. :setting:`TEST_DEPENDENCIES` definition, an ``ImproperlyConfigured``
  135. exception will be raised.
  136. Advanced features of ``TransactionTestCase``
  137. ============================================
  138. .. attribute:: TransactionTestCase.available_apps
  139. .. warning::
  140. This attribute is a private API. It may be changed or removed without
  141. a deprecation period in the future, for instance to accommodate changes
  142. in application loading.
  143. It's used to optimize Django's own test suite, which contains hundreds
  144. of models but no relations between models in different applications.
  145. By default, ``available_apps`` is set to ``None``. After each test, Django
  146. calls :djadmin:`flush` to reset the database state. This empties all tables
  147. and emits the :data:`~django.db.models.signals.post_migrate` signal, which
  148. re-creates one content type and three permissions for each model. This
  149. operation gets expensive proportionally to the number of models.
  150. Setting ``available_apps`` to a list of applications instructs Django to
  151. behave as if only the models from these applications were available. The
  152. behavior of ``TransactionTestCase`` changes as follows:
  153. - :data:`~django.db.models.signals.post_migrate` is fired before each
  154. test to create the content types and permissions for each model in
  155. available apps, in case they're missing.
  156. - After each test, Django empties only tables corresponding to models in
  157. available apps. However, at the database level, truncation may cascade to
  158. related models in unavailable apps. Furthermore
  159. :data:`~django.db.models.signals.post_migrate` isn't fired; it will be
  160. fired by the next ``TransactionTestCase``, after the correct set of
  161. applications is selected.
  162. Since the database isn't fully flushed, if a test creates instances of
  163. models not included in ``available_apps``, they will leak and they may
  164. cause unrelated tests to fail. Be careful with tests that use sessions;
  165. the default session engine stores them in the database.
  166. Since :data:`~django.db.models.signals.post_migrate` isn't emitted after
  167. flushing the database, its state after a ``TransactionTestCase`` isn't the
  168. same as after a ``TestCase``: it's missing the rows created by listeners
  169. to :data:`~django.db.models.signals.post_migrate`. Considering the
  170. :ref:`order in which tests are executed <order-of-tests>`, this isn't an
  171. issue, provided either all ``TransactionTestCase`` in a given test suite
  172. declare ``available_apps``, or none of them.
  173. ``available_apps`` is mandatory in Django's own test suite.
  174. .. attribute:: TransactionTestCase.reset_sequences
  175. Setting ``reset_sequences = True`` on a ``TransactionTestCase`` will make
  176. sure sequences are always reset before the test run::
  177. class TestsThatDependsOnPrimaryKeySequences(TransactionTestCase):
  178. reset_sequences = True
  179. def test_animal_pk(self):
  180. lion = Animal.objects.create(name="lion", sound="roar")
  181. # lion.pk is guaranteed to always be 1
  182. self.assertEqual(lion.pk, 1)
  183. Unless you are explicitly testing primary keys sequence numbers, it is
  184. recommended that you do not hard code primary key values in tests.
  185. Using ``reset_sequences = True`` will slow down the test, since the primary
  186. key reset is an relatively expensive database operation.
  187. Using the Django test runner to test reusable applications
  188. ==========================================================
  189. If you are writing a :doc:`reusable application </intro/reusable-apps>`
  190. you may want to use the Django test runner to run your own test suite
  191. and thus benefit from the Django testing infrastructure.
  192. A common practice is a *tests* directory next to the application code, with the
  193. following structure::
  194. runtests.py
  195. polls/
  196. __init__.py
  197. models.py
  198. ...
  199. tests/
  200. __init__.py
  201. models.py
  202. test_settings.py
  203. tests.py
  204. Let's take a look inside a couple of those files:
  205. .. snippet::
  206. :filename: runtests.py
  207. #!/usr/bin/env python
  208. import os
  209. import sys
  210. import django
  211. from django.conf import settings
  212. from django.test.utils import get_runner
  213. if __name__ == "__main__":
  214. os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
  215. django.setup()
  216. TestRunner = get_runner(settings)
  217. test_runner = TestRunner()
  218. failures = test_runner.run_tests(["tests"])
  219. sys.exit(bool(failures))
  220. This is the script that you invoke to run the test suite. It sets up the
  221. Django environment, creates the test database and runs the tests.
  222. For the sake of clarity, this example contains only the bare minimum
  223. necessary to use the Django test runner. You may want to add
  224. command-line options for controlling verbosity, passing in specific test
  225. labels to run, etc.
  226. .. snippet::
  227. :filename: tests/test_settings.py
  228. SECRET_KEY = 'fake-key'
  229. INSTALLED_APPS = [
  230. "tests",
  231. ]
  232. This file contains the :doc:`Django settings </topics/settings>`
  233. required to run your app's tests.
  234. Again, this is a minimal example; your tests may require additional
  235. settings to run.
  236. Since the *tests* package is included in :setting:`INSTALLED_APPS` when
  237. running your tests, you can define test-only models in its ``models.py``
  238. file.
  239. .. _other-testing-frameworks:
  240. Using different testing frameworks
  241. ==================================
  242. Clearly, :mod:`unittest` is not the only Python testing framework. While Django
  243. doesn't provide explicit support for alternative frameworks, it does provide a
  244. way to invoke tests constructed for an alternative framework as if they were
  245. normal Django tests.
  246. When you run ``./manage.py test``, Django looks at the :setting:`TEST_RUNNER`
  247. setting to determine what to do. By default, :setting:`TEST_RUNNER` points to
  248. ``'django.test.runner.DiscoverRunner'``. This class defines the default Django
  249. testing behavior. This behavior involves:
  250. #. Performing global pre-test setup.
  251. #. Looking for tests in any file below the current directory whose name matches
  252. the pattern ``test*.py``.
  253. #. Creating the test databases.
  254. #. Running ``migrate`` to install models and initial data into the test
  255. databases.
  256. #. Running the tests that were found.
  257. #. Destroying the test databases.
  258. #. Performing global post-test teardown.
  259. If you define your own test runner class and point :setting:`TEST_RUNNER` at
  260. that class, Django will execute your test runner whenever you run
  261. ``./manage.py test``. In this way, it is possible to use any test framework
  262. that can be executed from Python code, or to modify the Django test execution
  263. process to satisfy whatever testing requirements you may have.
  264. .. _topics-testing-test_runner:
  265. Defining a test runner
  266. ----------------------
  267. .. currentmodule:: django.test.runner
  268. A test runner is a class defining a ``run_tests()`` method. Django ships
  269. with a ``DiscoverRunner`` class that defines the default Django testing
  270. behavior. This class defines the ``run_tests()`` entry point, plus a
  271. selection of other methods that are used to by ``run_tests()`` to set up,
  272. execute and tear down the test suite.
  273. .. class:: DiscoverRunner(pattern='test*.py', top_level=None, verbosity=1, interactive=True, failfast=True, keepdb=False, reverse=False, debug_sql=False, **kwargs)
  274. ``DiscoverRunner`` will search for tests in any file matching ``pattern``.
  275. ``top_level`` can be used to specify the directory containing your
  276. top-level Python modules. Usually Django can figure this out automatically,
  277. so it's not necessary to specify this option. If specified, it should
  278. generally be the directory containing your ``manage.py`` file.
  279. ``verbosity`` determines the amount of notification and debug information
  280. that will be printed to the console; ``0`` is no output, ``1`` is normal
  281. output, and ``2`` is verbose output.
  282. If ``interactive`` is ``True``, the test suite has permission to ask the
  283. user for instructions when the test suite is executed. An example of this
  284. behavior would be asking for permission to delete an existing test
  285. database. If ``interactive`` is ``False``, the test suite must be able to
  286. run without any manual intervention.
  287. If ``failfast`` is ``True``, the test suite will stop running after the
  288. first test failure is detected.
  289. If ``keepdb`` is ``True``, the test suite will use the existing database,
  290. or create one if necessary. If ``False``, a new database will be created,
  291. prompting the user to remove the existing one, if present.
  292. If ``reverse`` is ``True``, test cases will be executed in the opposite
  293. order. This could be useful to debug tests that aren't properly isolated
  294. and have side effects. :ref:`Grouping by test class <order-of-tests>` is
  295. preserved when using this option.
  296. If ``debug_sql`` is ``True``, failing test cases will output SQL queries
  297. logged to the :ref:`django.db.backends logger <django-db-logger>` as well
  298. as the traceback. If ``verbosity`` is ``2``, then queries in all tests are
  299. output.
  300. Django may, from time to time, extend the capabilities of the test runner
  301. by adding new arguments. The ``**kwargs`` declaration allows for this
  302. expansion. If you subclass ``DiscoverRunner`` or write your own test
  303. runner, ensure it accepts ``**kwargs``.
  304. Your test runner may also define additional command-line options.
  305. Create or override an ``add_arguments(cls, parser)`` class method and add
  306. custom arguments by calling ``parser.add_argument()`` inside the method, so
  307. that the :djadmin:`test` command will be able to use those arguments.
  308. .. versionchanged:: 1.8
  309. Previously, you had to provide an ``option_list`` attribute to a
  310. subclassed test runner to add options to the list of command-line
  311. options that the :djadmin:`test` command could use.
  312. The ``keepdb``, ``reverse``, and ``debug_sql`` arguments were added.
  313. Attributes
  314. ~~~~~~~~~~
  315. .. attribute:: DiscoverRunner.test_suite
  316. The class used to build the test suite. By default it is set to
  317. ``unittest.TestSuite``. This can be overridden if you wish to implement
  318. different logic for collecting tests.
  319. .. attribute:: DiscoverRunner.test_runner
  320. This is the class of the low-level test runner which is used to execute
  321. the individual tests and format the results. By default it is set to
  322. ``unittest.TextTestRunner``. Despite the unfortunate similarity in
  323. naming conventions, this is not the same type of class as
  324. ``DiscoverRunner``, which covers a broader set of responsibilities. You
  325. can override this attribute to modify the way tests are run and reported.
  326. .. attribute:: DiscoverRunner.test_loader
  327. This is the class that loads tests, whether from TestCases or modules or
  328. otherwise and bundles them into test suites for the runner to execute.
  329. By default it is set to ``unittest.defaultTestLoader``. You can override
  330. this attribute if your tests are going to be loaded in unusual ways.
  331. .. attribute:: DiscoverRunner.option_list
  332. This is the tuple of ``optparse`` options which will be fed into the
  333. management command's ``OptionParser`` for parsing arguments. See the
  334. documentation for Python's ``optparse`` module for more details.
  335. .. deprecated:: 1.8
  336. You should now override the :meth:`~DiscoverRunner.add_arguments` class
  337. method to add custom arguments accepted by the :djadmin:`test`
  338. management command.
  339. Methods
  340. ~~~~~~~
  341. .. method:: DiscoverRunner.run_tests(test_labels, extra_tests=None, **kwargs)
  342. Run the test suite.
  343. ``test_labels`` allows you to specify which tests to run and supports
  344. several formats (see :meth:`DiscoverRunner.build_suite` for a list of
  345. supported formats).
  346. ``extra_tests`` is a list of extra ``TestCase`` instances to add to the
  347. suite that is executed by the test runner. These extra tests are run
  348. in addition to those discovered in the modules listed in ``test_labels``.
  349. This method should return the number of tests that failed.
  350. .. classmethod:: DiscoverRunner.add_arguments(parser)
  351. .. versionadded:: 1.8
  352. Override this class method to add custom arguments accepted by the
  353. :djadmin:`test` management command. See
  354. :py:meth:`argparse.ArgumentParser.add_argument()` for details about adding
  355. arguments to a parser.
  356. .. method:: DiscoverRunner.setup_test_environment(**kwargs)
  357. Sets up the test environment by calling
  358. :func:`~django.test.utils.setup_test_environment` and setting
  359. :setting:`DEBUG` to ``False``.
  360. .. method:: DiscoverRunner.build_suite(test_labels, extra_tests=None, **kwargs)
  361. Constructs a test suite that matches the test labels provided.
  362. ``test_labels`` is a list of strings describing the tests to be run. A test
  363. label can take one of four forms:
  364. * ``path.to.test_module.TestCase.test_method`` -- Run a single test method
  365. in a test case.
  366. * ``path.to.test_module.TestCase`` -- Run all the test methods in a test
  367. case.
  368. * ``path.to.module`` -- Search for and run all tests in the named Python
  369. package or module.
  370. * ``path/to/directory`` -- Search for and run all tests below the named
  371. directory.
  372. If ``test_labels`` has a value of ``None``, the test runner will search for
  373. tests in all files below the current directory whose names match its
  374. ``pattern`` (see above).
  375. ``extra_tests`` is a list of extra ``TestCase`` instances to add to the
  376. suite that is executed by the test runner. These extra tests are run
  377. in addition to those discovered in the modules listed in ``test_labels``.
  378. Returns a ``TestSuite`` instance ready to be run.
  379. .. method:: DiscoverRunner.setup_databases(**kwargs)
  380. Creates the test databases.
  381. Returns a data structure that provides enough detail to undo the changes
  382. that have been made. This data will be provided to the ``teardown_databases()``
  383. function at the conclusion of testing.
  384. .. method:: DiscoverRunner.run_suite(suite, **kwargs)
  385. Runs the test suite.
  386. Returns the result produced by the running the test suite.
  387. .. method:: DiscoverRunner.teardown_databases(old_config, **kwargs)
  388. Destroys the test databases, restoring pre-test conditions.
  389. ``old_config`` is a data structure defining the changes in the
  390. database configuration that need to be reversed. It is the return
  391. value of the ``setup_databases()`` method.
  392. .. method:: DiscoverRunner.teardown_test_environment(**kwargs)
  393. Restores the pre-test environment.
  394. .. method:: DiscoverRunner.suite_result(suite, result, **kwargs)
  395. Computes and returns a return code based on a test suite, and the result
  396. from that test suite.
  397. Testing utilities
  398. -----------------
  399. django.test.utils
  400. ~~~~~~~~~~~~~~~~~
  401. .. module:: django.test.utils
  402. :synopsis: Helpers to write custom test runners.
  403. To assist in the creation of your own test runner, Django provides a number of
  404. utility methods in the ``django.test.utils`` module.
  405. .. function:: setup_test_environment()
  406. Performs any global pre-test setup, such as the installing the
  407. instrumentation of the template rendering system and setting up
  408. the dummy email outbox.
  409. .. function:: teardown_test_environment()
  410. Performs any global post-test teardown, such as removing the black
  411. magic hooks into the template system and restoring normal email
  412. services.
  413. django.db.connection.creation
  414. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  415. .. currentmodule:: django.db.connection.creation
  416. The creation module of the database backend also provides some utilities that
  417. can be useful during testing.
  418. .. function:: create_test_db([verbosity=1, autoclobber=False, serialize=True, keepdb=False])
  419. Creates a new test database and runs ``migrate`` against it.
  420. ``verbosity`` has the same behavior as in ``run_tests()``.
  421. ``autoclobber`` describes the behavior that will occur if a
  422. database with the same name as the test database is discovered:
  423. * If ``autoclobber`` is ``False``, the user will be asked to
  424. approve destroying the existing database. ``sys.exit`` is
  425. called if the user does not approve.
  426. * If autoclobber is ``True``, the database will be destroyed
  427. without consulting the user.
  428. ``serialize`` determines if Django serializes the database into an
  429. in-memory JSON string before running tests (used to restore the database
  430. state between tests if you don't have transactions). You can set this to
  431. ``False`` to speed up creation time if you don't have any test classes
  432. with :ref:`serialized_rollback=True <test-case-serialized-rollback>`.
  433. If you are using the default test runner, you can control this with the
  434. the :setting:`SERIALIZE <TEST_SERIALIZE>` entry in the :setting:`TEST
  435. <DATABASE-TEST>` dictionary.
  436. ``keepdb`` determines if the test run should use an existing
  437. database, or create a new one. If ``True``, the existing
  438. database will be used, or created if not present. If ``False``,
  439. a new database will be created, prompting the user to remove
  440. the existing one, if present.
  441. Returns the name of the test database that it created.
  442. ``create_test_db()`` has the side effect of modifying the value of
  443. :setting:`NAME` in :setting:`DATABASES` to match the name of the test
  444. database.
  445. .. versionchanged:: 1.8
  446. The ``keepdb`` argument was added.
  447. .. function:: destroy_test_db(old_database_name, [verbosity=1, keepdb=False])
  448. Destroys the database whose name is the value of :setting:`NAME` in
  449. :setting:`DATABASES`, and sets :setting:`NAME` to the value of
  450. ``old_database_name``.
  451. The ``verbosity`` argument has the same behavior as for
  452. :class:`~django.test.runner.DiscoverRunner`.
  453. If the ``keepdb`` argument is ``True``, then the connection to the
  454. database will be closed, but the database will not be destroyed.
  455. .. versionchanged:: 1.8
  456. The ``keepdb`` argument was added.
  457. .. _topics-testing-code-coverage:
  458. Integration with coverage.py
  459. ============================
  460. Code coverage describes how much source code has been tested. It shows which
  461. parts of your code are being exercised by tests and which are not. It's an
  462. important part of testing applications, so it's strongly recommended to check
  463. the coverage of your tests.
  464. Django can be easily integrated with `coverage.py`_, a tool for measuring code
  465. coverage of Python programs. First, `install coverage.py`_. Next, run the
  466. following from your project folder containing ``manage.py``::
  467. coverage run --source='.' manage.py test myapp
  468. This runs your tests and collects coverage data of the executed files in your
  469. project. You can see a report of this data by typing following command::
  470. coverage report
  471. Note that some Django code was executed while running tests, but it is not
  472. listed here because of the ``source`` flag passed to the previous command.
  473. For more options like annotated HTML listings detailing missed lines, see the
  474. `coverage.py`_ docs.
  475. .. _coverage.py: http://nedbatchelder.com/code/coverage/
  476. .. _install coverage.py: https://pypi.python.org/pypi/coverage