plugins.rst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. .. Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
  2. .. For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
  3. .. _plugins:
  4. =======
  5. Plugins
  6. =======
  7. .. :history: 20150124T143000, new page.
  8. .. :history: 20150802T174600, updated for 4.0b1
  9. Coverage.py's behavior can be extended with third-party plugins. A plugin is a
  10. separately installed Python class that you register in your .coveragerc.
  11. Plugins can be used to implement coverage measurement for non-Python files.
  12. Plugins are only supported with the :ref:`C extension <install_extension>`,
  13. which must be installed for plugins to work.
  14. Information about using plugins is on this page. To write a plugin, see
  15. :ref:`api_plugin`.
  16. .. versionadded:: 4.0
  17. Using plugins
  18. -------------
  19. To use a coverage.py plugin, you install it, and configure it. For this
  20. example, let's say there's a Python package called ``something`` that provides a
  21. coverage.py plugin called ``something.plugin``.
  22. #. Install the plugin's package as you would any other Python package::
  23. pip install something
  24. #. Configure coverage.py to use the plugin. You do this by editing (or
  25. creating) your .coveragerc file, as described in :ref:`config`. The
  26. ``plugins`` setting indicates your plugin. It's a list of importable module
  27. names of plugins::
  28. [run]
  29. plugins =
  30. something.plugin
  31. #. If the plugin needs its own configuration, you can add those settings in
  32. the .coveragerc file in a section named for the plugin::
  33. [something.plugin]
  34. option1 = True
  35. option2 = abc.foo
  36. Check the documentation for the plugin to see if it takes any options, and
  37. what they are.
  38. #. Run your tests with coverage.py as you usually would. If you get a message
  39. like "Plugin file tracers (something.plugin) aren't supported with
  40. PyTracer," then you don't have the :ref:`C extension <install_extension>`
  41. installed.
  42. Available plugins
  43. -----------------
  44. Some coverage.py plugins you might find useful:
  45. * `Django template coverage.py plugin`__: for measuring coverage in Django
  46. templates.
  47. .. __: https://pypi.python.org/pypi/django_coverage_plugin
  48. * `Mako template coverage plugin`__: for measuring coverage in Mako templates.
  49. Doesn't work yet, probably needs some changes in Mako itself.
  50. .. __: https://bitbucket.org/ned/coverage-mako-plugin