Consolidate tox environments (#328)

This commit is contained in:
Sorin Sbarnea 2020-08-11 13:54:34 +01:00 committed by GitHub
parent 8a2dded57f
commit cbfc38d4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 41 deletions

View File

@ -27,10 +27,6 @@ jobs:
python: 3.6
env: TOXENV=py36
-
python: 3.6
env: TOXENV=py36-ansi2html
-
python: 3.7
dist: xenial
@ -41,29 +37,15 @@ jobs:
python: 3.8
env: TOXENV=py38
-
python: 3.7
dist: xenial
sudo: required
env: TOXENV=py37-ansi2html
- name: devel
python: 3.8
dist: xenial
env: TOXENV=devel
-
python: 3.8
env: TOXENV=py38-ansi2html
-
python: pypy3
env: TOXENV=pypy3
-
python: pypy3
env: TOXENV=pypy3-ansi2html
- stage: deploy
python: 3.7
dist: xenial

View File

@ -4,6 +4,8 @@
from base64 import b64encode, b64decode
from collections import OrderedDict
from functools import lru_cache
import importlib
from os.path import isfile
import datetime
import json
@ -17,14 +19,6 @@ import re
from html import escape
import pytest
try:
from ansi2html import Ansi2HTMLConverter, style
ANSI = True
except ImportError:
# ansi2html is not installed
ANSI = False
from py.xml import html, raw
from . import extras
@ -33,6 +27,16 @@ from . import __version__, __pypi_url__
from _pytest.logging import _remove_ansi_escape_sequences
@lru_cache()
def ansi_support():
try:
# from ansi2html import Ansi2HTMLConverter, style # NOQA
return importlib.import_module("ansi2html")
except ImportError:
# ansi2html is not installed
pass
def pytest_addhooks(pluginmanager):
from . import hooks
@ -290,8 +294,10 @@ class HTMLReport:
log.append(f" {header:-^80} ")
log.append(html.br())
if ANSI:
converter = Ansi2HTMLConverter(inline=False, escaped=False)
if ansi_support():
converter = ansi_support().Ansi2HTMLConverter(
inline=False, escaped=False
)
content = converter.convert(content, full=False)
else:
content = _remove_ansi_escape_sequences(content)
@ -413,13 +419,13 @@ class HTMLReport:
__name__, os.path.join("resources", "style.css")
).decode("utf-8")
if ANSI:
if ansi_support():
ansi_css = [
"\n/******************************",
" * ANSI2HTML STYLES",
" ******************************/\n",
]
ansi_css.extend([str(r) for r in style.get_styles()])
ansi_css.extend([str(r) for r in ansi_support().style.get_styles()])
self.style_css += "\n".join(ansi_css)
# <DF> Add user-provided CSS

View File

@ -809,14 +809,14 @@ class TestHTML:
assert result.ret == 0
assert_results(html, passed=1)
def test_ansi_color(self, testdir):
try:
import ansi2html # NOQA
@pytest.mark.parametrize(
"with_ansi", [True, False],
)
def test_ansi_color(self, testdir, mocker, with_ansi):
if not with_ansi:
mock_ansi_support = mocker.patch("pytest_html.plugin.ansi_support")
mock_ansi_support.return_value = None
ANSI = True
except ImportError:
# ansi2html is not installed
ANSI = False
pass_content = [
'<span class="ansi31">RCOLOR',
'<span class="ansi32">GCOLOR',
@ -834,7 +834,7 @@ class TestHTML:
result, html = run(testdir, "report.html", "--self-contained-html")
assert result.ret == 0
for content in pass_content:
if ANSI:
if with_ansi:
assert content in html
else:
assert content not in html

View File

@ -1,10 +1,10 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# Tox (https://tox.readthedocs.io) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py{36,37,38,py3}{,-ansi2html}, linting
envlist = py{36,37,38,py3}, linting
[testenv]
setenv = PYTHONDONTWRITEBYTECODE=1
@ -12,7 +12,7 @@ deps =
pytest-xdist
pytest-rerunfailures
pytest-mock
py{36,37,38,py3}-ansi2html: ansi2html
ansi2html # soft-dependency
commands = pytest -v -r a --color=yes --html={envlogdir}/report.html --self-contained-html {posargs}
[testenv:linting]