8000 Disable ANSI codes support by default · pytest-dev/pytest-html@dba1e1b · GitHub
[go: up one dir, main page]

Skip to content

Commit dba1e1b

Browse files
committed
Disable ANSI codes support by default
Due to ansi2html having a less permissive license, remove it as a dependency.
1 parent 0b8c46c commit dba1e1b

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Release Notes
22
-------------
33

4+
**1.12.1 (2016-12-19)**
5+
6+
* Disable ANSI codes support by default due to dependency on
7+
`ansi2html <https://pypi.python.org/pypi/ansi2html/>`_ package with less
8+
permissive licensing
9+
410
**1.12.0 (2016-11-30)**
511

612
* Add support for JPG and SVG images

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ Then run your tests with:
4343
4444
$ pytest --html=report.html
4545
46+
ANSI codes
47+
----------
48+
49+
Note that ANSI code support depends on the
50+
`ansi2html <https://pypi.python.org/pypi/ansi2html/>`_ package. Due to the use
51+
of a less permissive license, this package is not included as a dependency. If
52+
you have this package installed, then ANSI codes will be converted to HTML in
53+
your report.
54+
4655
Creating a self-contained report
4756
----------------------------------
4857

pytest_html/plugin.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
import bisect
1616
import hashlib
1717

18-
from ansi2html import Ansi2HTMLConverter, style
18+
try:
19+
from ansi2html import Ansi2HTMLConverter, style
20+
ANSI = True
21+
except ImportError:
22+
# ansi2html is not installed
23+
ANSI = False
24+
1925
import pytest
2026
from py.xml import html, raw
2127

@@ -233,8 +239,9 @@ def append_log_html(self, report, additional_html):
233239
for header, content in report.sections:
234240
log.append(' {0} '.format(header).center(80, '-'))
235241
log.append(html.br())
236-
content = Ansi2HTMLConverter(inline=False).convert(content,
237-
full=False)
242+
if ANSI:
243+
converter = Ansi2HTMLConverter(inline=False)
244+
content = converter.convert(content, full=False)
238245
log.append(raw(content))
239246

240247
if len(log) == 0:
@@ -297,12 +304,13 @@ def _generate_report(self, session):
297304
if PY3:
298305
self.style_css = self.style_css.decode('utf-8')
299306

300-
ansi_css = [
301-
'\n/******************************',
302-
' * ANSI2HTML STYLES',
303-
' ******************************/\n']
304-
ansi_css.extend([str(r) for r in style.get_styles()])
305-
self.style_css += '\n'.join(ansi_css)
307+
if ANSI:
308+
ansi_css = [
309+
'\n/******************************',
310+
' * ANSI2HTML STYLES',
311+
' ******************************/\n']
312+
ansi_css.extend([str(r) for r in style.get_styles()])
313+
self.style_css += '\n'.join(ansi_css)
306314

307315
css_href = '{0}/{1}'.format('assets', 'style.css')
308316
html_css = html.link(href=css_href, rel='stylesheet',

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
package_data={'pytest_html': ['resources/*']},
1212
entry_points={'pytest11': ['html = pytest_html.plugin']},
1313
setup_requires=['setuptools_scm'],
14-
install_requires=['ansi2html>=1.1.1',
15-
'pytest>=2.3'],
14+
install_requires=['pytest>=2.3'],
1615
license='Mozilla Public License 2.0 (MPL 2.0)',
1716
keywords='py.test pytest html report',
1817
classifiers=[

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ envlist = py{26,27,33,34,35,py,py3}-pytest{29,30}, flake8
99
[testenv]
1010
commands = py.test -v -r a {posargs}
1111
deps =
12+
ansi2html==1.1.1
1213
pytest29: pytest==2.9.2
1314
pytest30: pytest==3.0.4
1415
pytest-xdist

0 commit comments

Comments
 (0)
0