Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release Notes
-------------

**1.13.0 (2016-12-19)**

* Disable ANSI codes support by default due to dependency on
`ansi2html <https://pypi.python.org/pypi/ansi2html/>`_ package with less
permissive licensing

**1.12.0 (2016-11-30)**

* Add support for JPG and SVG images
Expand Down
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ Then run your tests with:

$ pytest --html=report.html

ANSI codes
----------

Note that ANSI code support depends on the
`ansi2html <https://pypi.python.org/pypi/ansi2html/>`_ package. Due to the use
of a less permissive license, this package is not included as a dependency. If
you have this package installed, then ANSI codes will be converted to HTML in
your report.

Creating a self-contained report
----------------------------------

Expand Down
26 changes: 17 additions & 9 deletions pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
import bisect
import hashlib

from ansi2html import Ansi2HTMLConverter, style
try:
from ansi2html import Ansi2HTMLConverter, style
ANSI = True
except ImportError:
# ansi2html is not installed
ANSI = False

import pytest
from py.xml import html, raw

Expand Down Expand Up @@ -233,8 +239,9 @@ def append_log_html(self, report, additional_html):
for header, content in report.sections:
log.append(' {0} '.format(header).center(80, '-'))
log.append(html.br())
content = Ansi2HTMLConverter(inline=False).convert(content,
full=False)
if ANSI:
converter = Ansi2HTMLConverter(inline=False)
content = converter.convert(content, full=False)
log.append(raw(content))

if len(log) == 0:
Expand Down Expand Up @@ -297,12 +304,13 @@ def _generate_report(self, session):
if PY3:
self.style_css = self.style_css.decode('utf-8')

ansi_css = [
'\n/******************************',
' * ANSI2HTML STYLES',
' ******************************/\n']
ansi_css.extend([str(r) for r in style.get_styles()])
self.style_css += '\n'.join(ansi_css)
if ANSI:
ansi_css = [
'\n/******************************',
' * ANSI2HTML STYLES',
' ******************************/\n']
ansi_css.extend([str(r) for r in style.get_styles()])
self.style_css += '\n'.join(ansi_css)

css_href = '{0}/{1}'.format('assets', 'style.css')
html_css = html.link(href=css_href, rel='stylesheet',
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
package_data={'pytest_html': ['resources/*']},
entry_points={'pytest11': ['html = pytest_html.plugin']},
setup_requires=['setuptools_scm'],
install_requires=['ansi2html>=1.1.1',
'pytest>=2.3'],
install_requires=['pytest>=2.3'],
license='Mozilla Public License 2.0 (MPL 2.0)',
keywords='py.test pytest html report',
classifiers=[
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ envlist = py{26,27,33,34,35,py,py3}-pytest{29,30}, flake8
[testenv]
commands = py.test -v -r a {posargs}
deps =
ansi2html==1.1.1
pytest29: pytest==2.9.2
pytest30: pytest==3.0.4
pytest-xdist
Expand Down