From 7f94aaec90414a0c81f18cad0a1fcd9475019359 Mon Sep 17 00:00:00 2001 From: Conor MacBride Date: Thu, 2 Jun 2022 21:53:19 +0100 Subject: [PATCH 1/2] Fix bug with splitting parametrized test name "a.b.test_c[x.y]" should give ("a.b", "test_c[x.y]") and not ("a.b.test_c[x", "y]") --- pytest_mpl/summary/html.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pytest_mpl/summary/html.py b/pytest_mpl/summary/html.py index 0f30566d..af87e39a 100644 --- a/pytest_mpl/summary/html.py +++ b/pytest_mpl/summary/html.py @@ -93,8 +93,9 @@ def __init__(self, name, item, id): # Name of test with module and test function together and separate self.full_name = name - self.name = name.split('.')[-1] - self.module = '.'.join(name.split('.')[:-1]) + without_parametrized_name = name.split("[")[0] + self.module = ".".join(without_parametrized_name.split(".")[:-1]) + self.name = name[len(self.module)+1:] # Additional classes to add to the result card self.classes = [f'{k}-{str(v).lower()}' for k, v in [ From dc12665fde2a0f4b6f1cbfe8fb1c0db27af6b5b9 Mon Sep 17 00:00:00 2001 From: Conor MacBride Date: Thu, 2 Jun 2022 21:58:07 +0100 Subject: [PATCH 2/2] urlencode image URLs The images are path safe but not URL safe. Parametrized tests can include characters such as "\" or "?" in their name which can lead to 404 errors in the HTML summary report. --- pytest_mpl/summary/templates/basic.html | 2 +- pytest_mpl/summary/templates/result.html | 10 +++++----- pytest_mpl/summary/templates/result_images.html | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pytest_mpl/summary/templates/basic.html b/pytest_mpl/summary/templates/basic.html index 27e6417c..1dfe55ef 100644 --- a/pytest_mpl/summary/templates/basic.html +++ b/pytest_mpl/summary/templates/basic.html @@ -73,7 +73,7 @@

Image test comparison

{%- endif %} {% macro image(file) -%} - {% if file %}{% endif %} + {% if file %}{% endif %} {%- endmacro -%} {{ image(result.baseline_image) }} {{ image(result.diff_image) }} diff --git a/pytest_mpl/summary/templates/result.html b/pytest_mpl/summary/templates/result.html index 6e7986bd..6c5dd9e3 100644 --- a/pytest_mpl/summary/templates/result.html +++ b/pytest_mpl/summary/templates/result.html @@ -12,19 +12,19 @@
{% if r.diff_image -%}
- diff image + diff image
- result image + result image
{%- else -%} - result image + result image {%- endif %}
{%- elif r.result_image -%} - result image + result image {%- elif r.baseline_image -%} - baseline image + baseline image {%- endif %} {% filter indent(width=8) -%} diff --git a/pytest_mpl/summary/templates/result_images.html b/pytest_mpl/summary/templates/result_images.html index 36ab2943..37d4590b 100644 --- a/pytest_mpl/summary/templates/result_images.html +++ b/pytest_mpl/summary/templates/result_images.html @@ -13,7 +13,7 @@
{{ r.name }}
{{ name }}
{% if file -%} - {{ name }} + {{ name }} {%- endif %}