Skip to content

Commit 955eb44

Browse files
authored
Merge branch 'master' into fix-ansi-in-report
2 parents 0c7061c + 4dfec1c commit 955eb44

File tree

7 files changed

+46
-10
lines changed

7 files changed

+46
-10
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Release Notes
33

44
**2.1.2 (unreleased)**
55

6+
* Make the ``Results`` table ``Links`` column sortable (`#242 <https://github.com/pytest-dev/pytest-html/issues/242>`_)
7+
8+
* Thanks to `@vashirov <https://github.com/vashirov>`_ for reporting and `@gnikonorov <https://github.com/gnikonorov>`_ for the fix
9+
610
* Fix issue with missing image or video in extras. (`#265 <https://github.com/pytest-dev/pytest-html/issues/265>`_ and `pytest-selenium#237 <https://github.com/pytest-dev/pytest-selenium/issues/237>`_)
711

812
* Thanks to `@p00j4 <https://github.com/p00j4>`_ and `@anothermattbrown <https://github.com/anothermattbrown>`_ for reporting and `@christiansandberg <https://github.com/christiansandberg>`_ and `@superdodd <https://github.com/superdodd>`_ and `@dhalperi <https://github.com/dhalperi>`_ for the fix

pytest_html/plugin.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def pytest_addoption(parser):
7171
default=False,
7272
help="Open the report with all rows collapsed. Useful for very large reports",
7373
)
74+
parser.addini(
75+
"max_asset_filename_length",
76+
default=255,
77+
help="set the maximum filename length for assets "
78+
"attached to the html report.",
79+
)
7480

7581

7682
def pytest_configure(config):
@@ -147,6 +153,9 @@ def __init__(self, outcome, report, logfile, config):
147153
self.additional_html = []
148154
self.links_html = []
149155
self.self_contained = config.getoption("self_contained_html")
156+
self.max_asset_filename_length = int(
157+
config.getini("max_asset_filename_length")
158+
)
150159
self.logfile = logfile
151160
self.config = config
152161
self.row_table = self.row_extra = None
@@ -196,13 +205,12 @@ def __lt__(self, other):
196205
def create_asset(
197206
self, content, extra_index, test_index, file_extension, mode="w"
198207
):
199-
# 255 is the common max filename length on various filesystems
200208
asset_file_name = "{}_{}_{}.{}".format(
201209
re.sub(r"[^\w\.]", "_", self.test_id),
202210
str(extra_index),
203211
str(test_index),
204212
file_extension,
205-
)[-255:]
213+
)[-self.max_asset_filename_length :]
206214
asset_path = os.path.join(
207215
os.path.dirname(self.logfile), "assets", asset_file_name
208216
)
@@ -496,7 +504,7 @@ def generate_summary_item(self):
496504
html.th("Result", class_="sortable result initial-sort", col="result"),
497505
html.th("Test", class_="sortable", col="name"),
498506
html.th("Duration", class_="sortable numeric", col="duration"),
499-
html.th("Links"),
507+
html.th("Links", class_="sortable links", col="links"),
500508
]
501509
session.config.hook.pytest_html_results_table_header(cells=cells)
502510

pytest_html/resources/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function sort_column(elem) {
3232
key = key_num;
3333
} else if (elem.classList.contains('result')) {
3434
key = key_result;
35+
} else if (elem.classList.contains('links')) {
36+
key = key_link;
3537
} else {
3638
key = key_alpha;
3739
}
@@ -178,6 +180,13 @@ function key_num(col_index) {
178180
};
179181
}
180182

183+
function key_link(col_index) {
184+
return function(elem) {
185+
dataCell = elem.childNodes[1].childNodes[col_index].firstChild
186+
return dataCell == null ? "" : dataCell.innerText.toLowerCase();
187+
};
188+
}
189+
181190
function key_result(col_index) {
182191
return function(elem) {
183192
var strings = ['Error', 'Failed', 'Rerun', 'XFailed', 'XPassed',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
package_data={"pytest_html": ["resources/*"]},
1313
entry_points={"pytest11": ["html = pytest_html.plugin"]},
1414
setup_requires=["setuptools_scm"],
15-
install_requires=["pytest>=5.0", "pytest-metadata"],
15+
install_requires=["pytest>=5.0,!=6.0.0", "pytest-metadata"],
1616
license="Mozilla Public License 2.0 (MPL 2.0)",
1717
keywords="py.test pytest html report",
1818
python_requires=">=3.6",

testing/js_test_report.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<th class="sortable result initial-sort" col="result">Result</th>
2121
<th class="sortable" col="name">Test</th>
2222
<th class="sortable numeric" col="duration">Duration</th>
23-
<th>Links</th></tr>
23+
<th class="sortable links" col="links">Links</th></tr>
2424
<tr hidden="true" id="not-found-message">
2525
<th colspan="5">No results found. Try to check the filters</th>
2626
</tr>
@@ -30,7 +30,7 @@
3030
<td class="col-result">Rerun</td>
3131
<td class="test-1 col-name">rerun.py::test_rexample_1</td>
3232
<td class="col-duration">1.00</td>
33-
<td class="col-links"></td></tr>
33+
<td class="col-links"><a class="url" href="http://www.google.com/" target="_blank">URL</a> </td></tr>
3434
<tr>
3535
<td class="extra" colspan="5">
3636
<div class="log">@pytest.mark.flaky(reruns=5)<br/> def test_example():<br/> import random<br/>&gt; assert random.choice([True, False])<br/><span class="error">E assert False</span><br/><span class="error">E + where False = &lt;bound method Random.choice of &lt;random.Random object at 0x7fe80b85f420&gt;&gt;([True, False])</span><br/><span class="error">E + where &lt;bound method Random.choice of &lt;random.Random object at 0x7fe80b85f420&gt;&gt; = &lt;module 'random' from '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.pyc'&gt;.choice</span><br/><br/>rerun.py:6: AssertionError<br/></div></td></tr></tbody>

testing/test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
'rerun results-table-row', 'passed results-table-row');
4949
sort_column_test('[col=duration]',
5050
'passed results-table-row', 'rerun results-table-row');
51+
52+
//links
53+
sort_column_test('[col=links]',
54+
'rerun results-table-row', 'passed results-table-row');
55+
sort_column_test('[col=links]',
56+
'passed results-table-row', 'rerun results-table-row');
5157
});
5258

5359
QUnit.test('filter_table', function(assert){
@@ -123,6 +129,6 @@ QUnit.test('find', function (assert) {
123129
});
124130

125131
QUnit.test('find_all', function(assert) {
126-
assert.equal(find_all('.sortable').length, 3);
132+
assert.equal(find_all('.sortable').length, 4);
127133
assert.equal(find_all('.not-in-table').length, 0);
128134
});

testing/test_pytest_html.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ def pytest_runtest_makereport(item, call):
566566
assert result.ret == 0
567567
assert '<a href="{0}"><img src="{0}"/>'.format(content) in html
568568

569-
def test_very_long_test_name(self, testdir):
569+
@pytest.mark.parametrize("max_asset_filename_length", [10, 100])
570+
def test_very_long_test_name(self, testdir, max_asset_filename_length):
570571
testdir.makeconftest(
571572
"""
572573
import pytest
@@ -587,8 +588,16 @@ def {test_name}():
587588
assert False
588589
"""
589590
)
590-
result, html = run(testdir)
591-
file_name = f"test_very_long_test_name.py__{test_name}_0_0.png"[-255:]
591+
testdir.makeini(
592+
f"""
593+
[pytest]
594+
max_asset_filename_length = {max_asset_filename_length}
595+
"""
596+
)
597+
result, html = run(testdir, "report.html")
598+
file_name = f"test_very_long_test_name.py__{test_name}_0_0.png"[
599+
-max_asset_filename_length:
600+
]
592601
src = "assets/" + file_name
593602
link = f'<a class="image" href="{src}" target="_blank">'
594603
img = f'<img src="{src}"/>'

0 commit comments

Comments
 (0)