METADATA 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. Metadata-Version: 2.0
  2. Name: pytest-html
  3. Version: 1.15.2
  4. Summary: pytest plugin for generating HTML reports
  5. Home-page: https://github.com/pytest-dev/pytest-html
  6. Author: Dave Hunt
  7. Author-email: dhunt@mozilla.com
  8. License: Mozilla Public License 2.0 (MPL 2.0)
  9. Keywords: py.test pytest html report
  10. Platform: UNKNOWN
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Framework :: Pytest
  13. Classifier: Intended Audience :: Developers
  14. Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
  15. Classifier: Operating System :: POSIX
  16. Classifier: Operating System :: Microsoft :: Windows
  17. Classifier: Operating System :: MacOS :: MacOS X
  18. Classifier: Topic :: Software Development :: Quality Assurance
  19. Classifier: Topic :: Software Development :: Testing
  20. Classifier: Topic :: Utilities
  21. Classifier: Programming Language :: Python
  22. Classifier: Programming Language :: Python :: 2.7
  23. Classifier: Programming Language :: Python :: 3.6
  24. Requires-Dist: pytest (>=3.0)
  25. Requires-Dist: pytest-metadata
  26. pytest-html
  27. ===========
  28. pytest-html is a plugin for `pytest <http://pytest.org>`_ that generates a
  29. HTML report for the test results.
  30. .. image:: https://img.shields.io/badge/license-MPL%202.0-blue.svg
  31. :target: https://github.com/pytest-dev/pytest-html/blob/master/LICENSE
  32. :alt: License
  33. .. image:: https://img.shields.io/pypi/v/pytest-html.svg
  34. :target: https://pypi.python.org/pypi/pytest-html/
  35. :alt: PyPI
  36. .. image:: https://img.shields.io/travis/pytest-dev/pytest-html.svg
  37. :target: https://travis-ci.org/pytest-dev/pytest-html/
  38. :alt: Travis
  39. .. image:: https://img.shields.io/github/issues-raw/pytest-dev/pytest-html.svg
  40. :target: https://github.com/pytest-dev/pytest-html/issues
  41. :alt: Issues
  42. .. image:: https://img.shields.io/requires/github/pytest-dev/pytest-html.svg
  43. :target: https://requires.io/github/pytest-dev/pytest-html/requirements/?branch=master
  44. :alt: Requirements
  45. Requirements
  46. ------------
  47. You will need the following prerequisites in order to use pytest-html:
  48. - Python 2.7, 3.6, PyPy, or PyPy3
  49. Installation
  50. ------------
  51. To install pytest-html:
  52. .. code-block:: bash
  53. $ pip install pytest-html
  54. Then run your tests with:
  55. .. code-block:: bash
  56. $ pytest --html=report.html
  57. ANSI codes
  58. ----------
  59. Note that ANSI code support depends on the
  60. `ansi2html <https://pypi.python.org/pypi/ansi2html/>`_ package. Due to the use
  61. of a less permissive license, this package is not included as a dependency. If
  62. you have this package installed, then ANSI codes will be converted to HTML in
  63. your report.
  64. Creating a self-contained report
  65. --------------------------------
  66. In order to respect the `Content Security Policy (CSP)
  67. <https://developer.mozilla.org/docs/Web/Security/CSP>`_,
  68. several assets such as CSS and images are stored separately by default.
  69. You can alternatively create a self-contained report, which can be more
  70. convenient when sharing your results. This can be done in the following way:
  71. .. code-block:: bash
  72. $ pytest --html=report.html --self-contained-html
  73. Images added as files or links are going to be linked as external resources,
  74. meaning that the standalone report HTML-file may not display these images
  75. as expected.
  76. The plugin will issue a warning when adding files or links to the standalone report.
  77. Enhancing reports
  78. -----------------
  79. Environment
  80. ~~~~~~~~~~~
  81. The *Environment* section is provided by the `pytest-metadata
  82. <https://pypi.python.org/pypi/pytest-metadata/>`_, plugin, and can be accessed
  83. via the :code:`pytest_configure` hook:
  84. .. code-block:: python
  85. def pytest_configure(config):
  86. config._metadata['foo'] = 'bar'
  87. Extra content
  88. ~~~~~~~~~~~~~
  89. You can add details to the HTML reports by creating an 'extra' list on the
  90. report object. Here are the types of extra content that can be added:
  91. ========== ============================================
  92. Type Example
  93. ========== ============================================
  94. Raw HTML ``extra.html('<div>Additional HTML</div>')``
  95. `JSON`_ ``extra.json({'name': 'pytest'})``
  96. Plain text ``extra.text('Add some simple Text')``
  97. URL ``extra.url('http://www.example.com/')``
  98. Image ``extra.image(image, mime_type='image/gif', extension='gif')``
  99. Image ``extra.image('/path/to/file.png')``
  100. Image ``extra.image('http://some_image.png')``
  101. ========== ============================================
  102. **Note**: When adding an image from file, the path can be either absolute
  103. or relative.
  104. **Note**: When using ``--self-contained-html``, images added as files or links
  105. may not work as expected, see section `Creating a self-contained report`_ for
  106. more info.
  107. There are also convenient types for several image formats:
  108. ============ ====================
  109. Image format Example
  110. ============ ====================
  111. PNG ``extra.png(image)``
  112. JPEG ``extra.jpg(image)``
  113. SVG ``extra.svg(image)``
  114. ============ ====================
  115. The following example adds the various types of extras using a
  116. :code:`pytest_runtest_makereport` hook, which can be implemented in a plugin or
  117. conftest.py file:
  118. .. code-block:: python
  119. import pytest
  120. @pytest.mark.hookwrapper
  121. def pytest_runtest_makereport(item, call):
  122. pytest_html = item.config.pluginmanager.getplugin('html')
  123. outcome = yield
  124. report = outcome.get_result()
  125. extra = getattr(report, 'extra', [])
  126. if report.when == 'call':
  127. # always add url to report
  128. extra.append(pytest_html.extras.url('http://www.example.com/'))
  129. xfail = hasattr(report, 'wasxfail')
  130. if (report.skipped and xfail) or (report.failed and not xfail):
  131. # only add additional html on failure
  132. extra.append(pytest_html.extras.html('<div>Additional HTML</div>'))
  133. report.extra = extra
  134. You can also specify the :code:`name` argument for all types other than :code:`html` which will change the title of the
  135. created hyper link:
  136. .. code-block:: python
  137. extra.append(pytest_html.extras.text('some string', name='Different title'))
  138. Modifying the results table
  139. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140. You can modify the columns by implementing custom hooks for the header and
  141. rows. The following example :code:`conftest.py` adds a description column with
  142. the test function docstring, adds a sortable time column, and removes the links
  143. column:
  144. .. code-block:: python
  145. from datetime import datetime
  146. from py.xml import html
  147. import pytest
  148. @pytest.mark.optionalhook
  149. def pytest_html_results_table_header(cells):
  150. cells.insert(2, html.th('Description'))
  151. cells.insert(0, html.th('Time', class_='sortable time', col='time'))
  152. cells.pop()
  153. @pytest.mark.optionalhook
  154. def pytest_html_results_table_row(report, cells):
  155. cells.insert(2, html.td(report.description))
  156. cells.insert(1, html.td(datetime.utcnow(), class_='col-time'))
  157. cells.pop()
  158. @pytest.mark.hookwrapper
  159. def pytest_runtest_makereport(item, call):
  160. outcome = yield
  161. report = outcome.get_result()
  162. report.description = str(item.function.__doc__)
  163. You can also remove results by implementing the
  164. :code:`pytest_html_results_table_row` hook and removing all cells. The
  165. following example removes all passed results from the report:
  166. .. code-block:: python
  167. import pytest
  168. @pytest.mark.optionalhook
  169. def pytest_html_results_table_row(report, cells):
  170. if report.passed:
  171. del cells[:]
  172. The log output and additional HTML can be modified by implementing the
  173. :code:`pytest_html_results_html` hook. The following example replaces all
  174. additional HTML and log output with a notice that the log is empty:
  175. .. code-block:: python
  176. import pytest
  177. @pytest.mark.optionalhook
  178. def pytest_html_results_table_html(report, data):
  179. if report.passed:
  180. del data[:]
  181. data.append(html.div('No log output captured.', class_='empty log'))
  182. Screenshots
  183. -----------
  184. .. image:: https://cloud.githubusercontent.com/assets/122800/11952194/62daa964-a88e-11e5-9745-2aa5b714c8bb.png
  185. :target: https://cloud.githubusercontent.com/assets/122800/11951695/f371b926-a88a-11e5-91c2-499166776bd3.png
  186. :alt: Enhanced HTML report
  187. Contributing
  188. ------------
  189. Fork the repository and submit PRs with bug fixes and enhancements, contributions are very welcome.
  190. Tests can be run locally with `tox`_, for example to execute tests for Python 2.7 and 3.6 execute::
  191. tox -e py27,py36
  192. .. _`tox`: https://tox.readthedocs.org/en/latest/
  193. Resources
  194. ---------
  195. - `Release Notes <http://github.com/pytest-dev/pytest-html/blob/master/CHANGES.rst>`_
  196. - `Issue Tracker <http://github.com/pytest-dev/pytest-html/issues>`_
  197. - `Code <http://github.com/pytest-dev/pytest-html/>`_
  198. .. _JSON: http://json.org/