-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconftest.py
74 lines (70 loc) · 3.15 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pytest
import os
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
if os.environ.get("REGRESSION_MODE") == "off":
yield
return
pytest_html = item.config.pluginmanager.getplugin("html")
outcome = yield
report = outcome.get_result()
extra = getattr(report, "extra", [])
if report.when == "call":
# always add url to report
properties = {}
for k, v in report.user_properties:
properties[k] = v
img = "file://{}/{}.png".format(properties["output"], properties["test_name"])
if properties.get("new-test", True):
extra.append(pytest_html.extras.html("<table>"))
extra.append(pytest_html.extras.html("<tr><th colspan='2'> Directory : {} Python script : {}.py </th></tr>".format(properties["directory"], properties["test_name"])))
extra.append(
pytest_html.extras.html(
"<tr><th colspan='2'>new test : {} </th></tr>".format(
properties["test_name"]
)
)
)
extra.append(pytest_html.extras.html("<tr>"))
extra.append(
pytest_html.extras.html(
"<td> <img src='{}' width='50%'/></td>".format(img)
)
)
extra.append(pytest_html.extras.html("<tr>"))
extra.append(pytest_html.extras.html("</table>"))
else:
diff = "file://{}".format(properties["diff-image"])
ref = "file://{}".format(properties["ref-image"])
extra.append(pytest_html.extras.html("<table>"))
extra.append(pytest_html.extras.html("<tr><th colspan='4'> Directory : {} Python script : {}.py [ ./update_ref.ksh -p {} -t {}]</th></tr>".format(properties["directory"], properties["test_name"],
properties["directory"], properties["test_name"])))
extra.append(
pytest_html.extras.html(
"<tr><th colspan='2'>Difference in pixels : {} Test : {} </th></tr>".format(
properties.get("diff", "undef"), properties["test_name"], properties["test_name"])
)
)
extra.append(pytest_html.extras.html("<tr>"))
extra.append(
pytest_html.extras.html(
"<td> <img src='{}' width='50%'/></td>".format(ref)
)
)
extra.append(
pytest_html.extras.html(
"<td> <img src='{}' width='50%'/></td>".format(diff)
)
)
extra.append(
pytest_html.extras.html(
"<td> <img src='{}' width='50%'/></td>".format(img)
)
)
extra.append(pytest_html.extras.html("<tr>"))
extra.append(pytest_html.extras.html("</table>"))
xfail = hasattr(report, "wasxfail")
if (report.skipped and xfail) or (report.failed and not xfail):
# only add additional html on failure
extra.append(pytest_html.extras.html("<div>Additional HTML</div>"))
report.extra = extra