This commit is contained in:
Darren Burns
2022-09-20 13:48:35 +01:00
parent d619dae510
commit 13b27e1fa3
5 changed files with 715 additions and 464 deletions

File diff suppressed because one or more lines are too long

View File

@@ -5,10 +5,10 @@ from functools import partial
from operator import attrgetter
from os import PathLike
from pathlib import Path
from typing import Union, List, Optional, Any, Callable
from typing import Union, List, Optional, Callable
import pytest
from _pytest.fixtures import FixtureDef, SubRequest, FixtureRequest
from _pytest.fixtures import FixtureRequest
from jinja2 import Template
from rich.console import Console
from rich.panel import Panel
@@ -49,20 +49,6 @@ class SvgSnapshotDiff:
line_number: int
#
# def pytest_runtestloop(session: "Session") -> Optional[object]:
@pytest.hookimpl(hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem: "pytest.Function") -> Optional[object]:
"""Call underlying test function.
Stops at first non-None result, see :ref:`firstresult`.
"""
# Before
yield
# After
def pytest_runtest_teardown(item: pytest.Item, nextitem: Optional[pytest.Item]) -> None:
"""Called to perform the teardown phase for a test item.
@@ -79,26 +65,6 @@ def pytest_runtest_teardown(item: pytest.Item, nextitem: Optional[pytest.Item])
"""
@pytest.hookimpl(hookwrapper=True)
def pytest_fixture_setup(
fixturedef: FixtureDef[Any], request: SubRequest
) -> Optional[object]:
"""Perform fixture setup execution.
:returns: The return value of the call to the fixture function.
Stops at first non-None result, see :ref:`firstresult`.
.. note::
If the fixture function returns None, other implementations of
this hook function will continue to be called, according to the
behavior of the :ref:`firstresult` option.
"""
value = yield
value = value.get_result()
value = repr(value)
def pytest_sessionfinish(
session: "pytest.Session",
exitstatus: Union[int, "pytest.ExitCode"],
@@ -120,7 +86,9 @@ def pytest_sessionfinish(
SvgSnapshotDiff(
snapshot=str(snapshot_svg),
actual=str(actual_svg),
file_similarity=100 * difflib.SequenceMatcher(a=str(snapshot_svg), b=str(actual_svg)).ratio(),
file_similarity=100 * difflib.SequenceMatcher(a=str(snapshot_svg),
b=str(
actual_svg)).ratio(),
test_name=name,
path=path,
line_number=line_index + 1,
@@ -143,8 +111,8 @@ def pytest_sessionfinish(
diffs=diffs,
passes=num_snapshots_passing,
fails=num_fails,
pass_percentage=100*(num_snapshots_passing/num_snapshot_tests),
fail_percentage=100*(num_fails/num_snapshot_tests),
pass_percentage=100 * (num_snapshots_passing / (num_snapshot_tests + 1)),
fail_percentage=100 * (num_fails / (num_snapshot_tests + 1)),
num_snapshot_tests=num_snapshot_tests,
now=datetime.utcnow()
)

File diff suppressed because one or more lines are too long

View File

@@ -49,7 +49,7 @@
<strong class="font-monospace">
{{ diff.test_name }}
</strong>
<span class="text-muted">({{ "%.2f"|format(diff.file_similarity) }}% similar)</span>
<span class="text-muted">({{ "%.2f"|format(diff.file_similarity) }}% source similarity)</span>
</div>
<span class="text-muted">{{ diff.path }}:{{ diff.line_number }}</span>
</div>

View File

@@ -6,9 +6,25 @@ def test_grid_layout_basic_overflow(snap_compare):
assert snap_compare("docs/examples/guide/layout/grid_layout2.py")
def test_combining_layouts(snap_compare):
assert snap_compare("docs/examples/guide/layout/combining_layouts.py")
def test_grid_layout_gutter(snap_compare):
assert snap_compare("docs/examples/guide/layout/grid_layout7_gutter.py")
def test_layers(snap_compare):
assert snap_compare("docs/examples/guide/layout/layers.py")
def test_center_layout(snap_compare):
assert snap_compare("docs/examples/guide/layout/center_layout.py")
def test_horizontal_layout(snap_compare):
assert snap_compare("docs/examples/guide/layout/horizontal_layout.py")
def test_vertical_layout(snap_compare):
assert snap_compare("docs/examples/guide/layout/vertical_layout.py")
def test_dock_layout_sidebar(snap_compare):
assert snap_compare("docs/examples/guide/layout/dock_layout2_sidebar.py")