Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
4eea1cc
fix conflict
BeyondEvil Jan 25, 2022
caca5a3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 25, 2022
680fdc1
fix main.js conflicts
BeyondEvil Jan 25, 2022
7a1db7d
Merge branch 'next-gen' of github.com:BeyondEvil/pytest-html into nex…
BeyondEvil Jan 25, 2022
b780107
fix js test
BeyondEvil Jan 25, 2022
4a324b7
fix resource (main.js) test
BeyondEvil Jan 25, 2022
f84c7d4
ignore linting old main.js
BeyondEvil Jan 25, 2022
ca59818
ignore more js-files for now
BeyondEvil Jan 25, 2022
e709710
sigh
BeyondEvil Jan 25, 2022
03f7bb8
lets skip eslint for now
BeyondEvil Jan 25, 2022
be20769
Merge branch 'next-gen' of github.com:pytest-dev/pytest-html into nex…
BeyondEvil Jan 26, 2022
b4295ea
add backend
BeyondEvil Jan 15, 2022
a52a505
split nextgen class
BeyondEvil Jan 16, 2022
82358d9
fix title
BeyondEvil Jan 20, 2022
e2e3b0a
cleanup
BeyondEvil Jan 25, 2022
1616434
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 21, 2022
efcc888
add --next-gen flag
BeyondEvil Jan 25, 2022
0302dc2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 25, 2022
ae221d9
revert change to report extra
BeyondEvil Jan 26, 2022
93fe901
ignore linting old main.js
BeyondEvil Jan 25, 2022
315c4fc
ignore more js-files for now
BeyondEvil Jan 25, 2022
e1740db
sigh
BeyondEvil Jan 25, 2022
0139f05
lets skip eslint for now
BeyondEvil Jan 25, 2022
65a8571
add backend
BeyondEvil Jan 15, 2022
b2600a7
split nextgen class
BeyondEvil Jan 16, 2022
8736ba6
fix title
BeyondEvil Jan 20, 2022
2cc756d
cleanup
BeyondEvil Jan 25, 2022
2c98fcb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 21, 2022
3b14d3f
add --next-gen flag
BeyondEvil Jan 25, 2022
f79c41b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 25, 2022
752a134
revert change to report extra
BeyondEvil Jan 26, 2022
137102c
Merge branch 'combined-fe-and-be' of github.com:BeyondEvil/pytest-htm…
BeyondEvil Feb 4, 2022
b47f5ce
filters style
drRedflint Feb 4, 2022
65f14cf
css and dom brush up
drRedflint Feb 27, 2022
1cf03fd
Buildable app
drRedflint Apr 17, 2022
8b034d8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 8, 2022
fcf598c
always store data in html
BeyondEvil Jun 11, 2022
b18a6f7
Always store data blob in file
BeyondEvil Jun 28, 2022
d351c59
Merge pull request #3 from BeyondEvil/jim/always-store-data-blob-in-file
BeyondEvil Jun 28, 2022
7a83890
json dump test data
BeyondEvil Jun 28, 2022
d006f31
Merge pull request #4 from BeyondEvil/jim/fix-json-output
BeyondEvil Jun 28, 2022
62f236a
read data from dom element
drRedflint Jun 28, 2022
ec97147
Merge pull request #5 from drRedflint/rely_on_data_prop
BeyondEvil Jun 28, 2022
e8860c7
manually initialize state
drRedflint Jun 28, 2022
82f36ff
minimalistic dataset
drRedflint Jun 28, 2022
82f2c57
Merge pull request #6 from drRedflint/fix_unittests
BeyondEvil Jun 28, 2022
a0ce218
simplify included files
BeyondEvil Jun 28, 2022
b0738d4
Merge pull request #7 from BeyondEvil/jim/simplify-resources
BeyondEvil Jul 10, 2022
d90aad0
Handle report extras
BeyondEvil Jul 15, 2022
858bb3e
Merge pull request #8 from BeyondEvil/jim/handle-extras
BeyondEvil Jul 20, 2022
f4b427e
Handle python report hooks
BeyondEvil Jul 20, 2022
1517a9f
imgviewer
drRedflint Jul 28, 2022
8b2d7f9
present name in image viewer and open img on click
drRedflint Jul 29, 2022
401f615
moar hooks
BeyondEvil Jul 31, 2022
edd8a9f
Merge pull request #9 from BeyondEvil/jim/handle-hooks
BeyondEvil Jul 31, 2022
57f7462
Merge branch 'combined-fe-and-be' into img_viewer
BeyondEvil Jul 31, 2022
ddda951
Merge pull request #10 from drRedflint/img_viewer
BeyondEvil Aug 1, 2022
3920f67
setup linter for project
drRedflint Aug 1, 2022
60c58ed
conform to styles
drRedflint Aug 1, 2022
6e6ba32
Merge pull request #13 from drRedflint/linter
BeyondEvil Aug 2, 2022
eb43828
show video in imageviewer (#14)
drRedflint Aug 7, 2022
223bc41
Chore: Pluralize extra (#15)
BeyondEvil Aug 8, 2022
72a9710
Add extras.HTML
BeyondEvil Aug 8, 2022
e39bc15
Merge pull request #17 from BeyondEvil/extras-html
BeyondEvil Aug 9, 2022
0f6f422
Move outcome handling to backend (#18)
BeyondEvil Aug 9, 2022
8c44788
Pass in text version of longrepr if present
BeyondEvil Aug 9, 2022
a0cb25c
Merge pull request #19 from BeyondEvil/jim/fix-log-longrepr
BeyondEvil Aug 10, 2022
0c31c36
make collapse/expand all functional (#20)
drRedflint Aug 11, 2022
2ba1d00
only create links for text, url and json (#22)
BeyondEvil Sep 3, 2022
a62de0b
make filter search case insensitive (#21)
drRedflint Sep 9, 2022
fd62881
add no log output captured string
BeyondEvil Oct 25, 2022
6400ef4
Query params (#25)
drRedflint Oct 25, 2022
eff9f0d
adjust tests (#26)
drRedflint Feb 11, 2023
23fef75
Duration format (#27)
drRedflint Feb 11, 2023
a355708
Beyondevil/cleanup (#28)
BeyondEvil Mar 5, 2023
a69ec13
Fix merge conflicts
BeyondEvil Mar 5, 2023
de247c2
Fix pre-commit issues
BeyondEvil Mar 5, 2023
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
Prev Previous commit
Next Next commit
add backend
  • Loading branch information
BeyondEvil committed Feb 4, 2022
commit 65a8571ccb51a69493a4191e01d6bd2450eadc38
File renamed without changes.
606 changes: 606 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
[tool.poetry]
name = "pytest-html"
description = "pytest plugin for generating HTML reports"
version = "4.0.0-next"
authors = ["Jim", "Victor"]

[tool.poetry.dependencies]
python = ">=3.6"
Jinja2 = "^2.11.3"

[tool.poetry.dev-dependencies]
black = "20.8b1"
flake8 = "3.8.4"
tox = "^3.23.1"
pytest = "^6.2.4"

[build-system]
requires = [
"pip >= 19.3.1",
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
url="https://github.com/pytest-dev/pytest-html",
package_dir={"": "src"},
packages=["pytest_html"],
package_data={"pytest_html": ["resources/*"]},
package_data={"pytest_html": ["resources/*", "scripts/*"]},
entry_points={"pytest11": ["html = pytest_html.plugin"]},
setup_requires=["setuptools_scm"],
install_requires=["pytest>=5.0,!=6.0.0", "pytest-metadata"],
install_requires=["pytest>=5.0,!=6.0.0", "pytest-metadata", "jinja2>=3.0,<4.0"],
license="Mozilla Public License 2.0 (MPL 2.0)",
keywords="py.test pytest html report",
python_requires=">=3.6",
Expand Down
10 changes: 5 additions & 5 deletions src/pytest_html/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@


def pytest_html_report_title(report):
""" Called before adding the title to the report """
"""Called before adding the title to the report"""


def pytest_html_results_summary(prefix, summary, postfix):
""" Called before adding the summary section to the report """
"""Called before adding the summary section to the report"""


def pytest_html_results_table_header(cells):
""" Called after building results table header. """
"""Called after building results table header."""


def pytest_html_results_table_row(report, cells):
""" Called after building results table row. """
"""Called after building results table row."""


def pytest_html_results_table_html(report, data):
""" Called after building results table additional HTML. """
"""Called after building results table additional HTML."""
130 changes: 100 additions & 30 deletions src/pytest_html/nextgen.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,108 @@
import datetime
import json
from typing import Any
from typing import Dict
import os

import pytest
import re
import shutil

from . import __version__
from .util import cleanup_unserializable, get_scripts

from jinja2 import Environment, FileSystemLoader, PackageLoader

from _pytest.pathlib import Path


class NextGenReport:
def __init__(self, config, data_file):
def __init__(self, report_path, config):
_plugin_path = os.path.dirname(__file__)
self._report_absolute_path = Path(report_path).absolute()
self._report_path = self._report_absolute_path.parent

self._assets_path = Path(self._report_path, "assets")
self._assets_path.mkdir(parents=True, exist_ok=True)

self._scripts_dest_path = Path(self._report_path, "scripts")
self._scripts_dest_path.mkdir(parents=True, exist_ok=True)
self._scripts_src_path = Path(_plugin_path, "scripts")

self._resources_path = Path(_plugin_path, "resources")

self._default_css_path = Path(self._resources_path, "style.css")

self._config = config
self._data_file = data_file
self._data_file = Path(self._assets_path, "test_data.js")
self._template = None
self._template_filename = "index.jinja2"

self._title = "Next Gen Report"
self._data = {
"title": self._title,
"collectedItems": 0,
"environment": {},
"tests": [],
}

self._data_file.parent.mkdir(parents=True, exist_ok=True)
def _generate_environment(self):
metadata = self._config._metadata
for key in metadata.keys():
value = metadata[key]
if self._is_redactable_environment_variable(key):
black_box_ascii_value = 0x2593
metadata[key] = "".join(chr(black_box_ascii_value) for _ in str(value))

return metadata

def _generate_report(self):
self._template = self._read_template()

# Copy scripts
scripts_dest = shutil.copytree(
self._scripts_src_path, self._scripts_dest_path, dirs_exist_ok=True
)

# Copy default css file (style.css) to assets directory
new_css_path = shutil.copy(self._default_css_path, self._assets_path)

generated = datetime.datetime.now()
css_files = [new_css_path] + self._config.getoption("css")
rendered_report = self._render_html(
"Test Report",
generated.strftime("%d-%b-%Y"),
generated.strftime("%H:%M:%S"),
__version__,
self._data_file.name,
css_files,
get_scripts(scripts_dest),
)

with self._report_absolute_path.open("w", encoding="utf-8") as f:
f.write(rendered_report)

def _is_redactable_environment_variable(self, environment_variable):
redactable_regexes = self._config.getini("environment_table_redact_list")
for redactable_regex in redactable_regexes:
if re.match(redactable_regex, environment_variable):
return True

return False

def _read_template(self):
env = Environment(
loader=FileSystemLoader(self._resources_path), autoescape=True
)

return env.get_template(self._template_filename)

def _render_html(self, title, date, time, version, data_file, styles, scripts):
return self._template.render(
title=title,
date=date,
time=time,
version=version,
data_file=data_file,
styles=styles,
scripts=scripts,
)

def _write(self):
try:
Expand All @@ -28,18 +112,17 @@ def _write(self):
data = json.dumps(data)

with self._data_file.open("w", buffering=1, encoding="UTF-8") as f:
f.write("const jsonData = ")
f.write(data)
f.write("\n")
f.write(f"const jsonData = {data}\n")

@pytest.hookimpl(trylast=True)
def pytest_sessionstart(self, session):
config = session.config
if hasattr(config, "_metadata") and config._metadata:
metadata = config._metadata
self._data["environment"] = metadata
self._data["environment"] = self._generate_environment()
self._write()

self._generate_report()

@pytest.hookimpl(trylast=True)
def pytest_collection_finish(self, session):
self._data["collectedItems"] = len(session.items)
Expand All @@ -51,24 +134,11 @@ def pytest_runtest_logreport(self, report):
config=self._config, report=report
)

# rename to "extras" since list
if hasattr(report, "extra"):
for extra in report.extra:
print(extra)
if extra["mime_type"] is not None and "image" in extra["mime_type"]:
data.update({"extras": extra})
# # TODO rename to "extras" since list
# if hasattr(report, "extra"):
# for extra in report.extra:
# if extra["mime_type"] is not None and "image" in extra["mime_type"]:
# data.update({"extras": extra})

self._data["tests"].append(data)
self._write()


def cleanup_unserializable(d: Dict[str, Any]) -> Dict[str, Any]:
"""Return new dict with entries that are not json serializable by their str()."""
result = {}
for k, v in d.items():
try:
json.dumps({k: v})
except TypeError:
v = str(v)
result[k] = v
return result
20 changes: 11 additions & 9 deletions src/pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ def pytest_configure(config):
if not hasattr(config, "workerinput"):
# prevent opening htmlpath on worker nodes (xdist)
config._html = HTMLReport(htmlpath, config)

config._next_gen = NextGenReport(config, Path("nextgendata.js"))
config.pluginmanager.register(config._html)
config.pluginmanager.register(config._next_gen)

# config._next_gen = NextGenReport(htmlpath, config)
# config.pluginmanager.register(config._next_gen)


def pytest_unconfigure(config):
Expand All @@ -93,10 +93,10 @@ def pytest_unconfigure(config):
del config._html
config.pluginmanager.unregister(html)

next_gen = getattr(config, "_next_gen", None)
if next_gen:
del config._next_gen
config.pluginmanager.unregister(next_gen)
# next_gen = getattr(config, "_next_gen", None)
# if next_gen:
# del config._next_gen
# config.pluginmanager.unregister(next_gen)


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
Expand All @@ -105,8 +105,10 @@ def pytest_runtest_makereport(item, call):
report = outcome.get_result()
if report.when == "call":
fixture_extras = getattr(item.config, "extras", [])
plugin_extras = getattr(report, "extra", [])
report.extra = fixture_extras + plugin_extras
plugin_extras = getattr(report, "extras", [])
# print("fix: ", fixture_extras)
# print("plugin: ", plugin_extras)
report.extras = fixture_extras + plugin_extras


@pytest.fixture
Expand Down
Binary file not shown.
Loading