|
9 | 9 | from pathlib import Path
|
10 | 10 |
|
11 | 11 | import pytest
|
12 |
| -from jinja2 import Environment |
13 |
| -from jinja2 import FileSystemLoader |
14 |
| -from jinja2 import select_autoescape |
15 | 12 |
|
16 | 13 | from pytest_html import __version__
|
17 | 14 | from pytest_html import extras
|
18 | 15 | from pytest_html.table import Header
|
19 | 16 | from pytest_html.table import Row
|
20 |
| -from pytest_html.util import _ansi_styles |
21 | 17 | from pytest_html.util import cleanup_unserializable
|
22 | 18 |
|
23 | 19 |
|
24 | 20 | class BaseReport:
|
25 |
| - def __init__(self, report_path, config, report_data, default_css="style.css"): |
| 21 | + def __init__(self, report_path, config, report_data, template, css): |
26 | 22 | self._report_path = Path(os.path.expandvars(report_path)).expanduser()
|
27 | 23 | self._report_path.parent.mkdir(parents=True, exist_ok=True)
|
28 |
| - self._resources_path = Path(__file__).parent.joinpath("resources") |
29 | 24 | self._config = config
|
30 |
| - self._template = _read_template([self._resources_path]) |
31 |
| - self._css = _process_css( |
32 |
| - Path(self._resources_path, default_css), self._config.getoption("css") |
33 |
| - ) |
| 25 | + self._template = template |
| 26 | + self._css = css |
34 | 27 | self._max_asset_filename_length = int(
|
35 | 28 | config.getini("max_asset_filename_length")
|
36 | 29 | )
|
@@ -224,32 +217,6 @@ def pytest_runtest_logreport(self, report):
|
224 | 217 | self._generate_report()
|
225 | 218 |
|
226 | 219 |
|
227 |
| -def _process_css(default_css, extra_css): |
228 |
| - with open(default_css, encoding="utf-8") as f: |
229 |
| - css = f.read() |
230 |
| - |
231 |
| - # Add user-provided CSS |
232 |
| - for path in extra_css: |
233 |
| - css += "\n/******************************" |
234 |
| - css += "\n * CUSTOM CSS" |
235 |
| - css += f"\n * {path}" |
236 |
| - css += "\n ******************************/\n\n" |
237 |
| - with open(path, encoding="utf-8") as f: |
238 |
| - css += f.read() |
239 |
| - |
240 |
| - # ANSI support |
241 |
| - if _ansi_styles: |
242 |
| - ansi_css = [ |
243 |
| - "\n/******************************", |
244 |
| - " * ANSI2HTML STYLES", |
245 |
| - " ******************************/\n", |
246 |
| - ] |
247 |
| - ansi_css.extend([str(r) for r in _ansi_styles]) |
248 |
| - css += "\n".join(ansi_css) |
249 |
| - |
250 |
| - return css |
251 |
| - |
252 |
| - |
253 | 220 | def _is_error(report):
|
254 | 221 | return report.when in ["setup", "teardown"] and report.outcome == "failed"
|
255 | 222 |
|
@@ -282,13 +249,3 @@ def _process_outcome(report):
|
282 | 249 | return "XFailed"
|
283 | 250 |
|
284 | 251 | return report.outcome.capitalize()
|
285 |
| - |
286 |
| - |
287 |
| -def _read_template(search_paths, template_name="index.jinja2"): |
288 |
| - env = Environment( |
289 |
| - loader=FileSystemLoader(search_paths), |
290 |
| - autoescape=select_autoescape( |
291 |
| - enabled_extensions=("jinja2",), |
292 |
| - ), |
293 |
| - ) |
294 |
| - return env.get_template(template_name) |
0 commit comments