Merge branch 'master' into fix-ansi-in-report

This commit is contained in:
Sorin Sbarnea 2020-08-10 13:16:46 +01:00 committed by GitHub
commit 955eb440cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 10 deletions

View File

@ -3,6 +3,10 @@ Release Notes
**2.1.2 (unreleased)**
* Make the ``Results`` table ``Links`` column sortable (`#242 <https://github.com/pytest-dev/pytest-html/issues/242>`_)
* Thanks to `@vashirov <https://github.com/vashirov>`_ for reporting and `@gnikonorov <https://github.com/gnikonorov>`_ for the fix
* 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>`_)
* 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

View File

@ -71,6 +71,12 @@ def pytest_addoption(parser):
default=False,
help="Open the report with all rows collapsed. Useful for very large reports",
)
parser.addini(
"max_asset_filename_length",
default=255,
help="set the maximum filename length for assets "
"attached to the html report.",
)
def pytest_configure(config):
@ -147,6 +153,9 @@ class HTMLReport:
self.additional_html = []
self.links_html = []
self.self_contained = config.getoption("self_contained_html")
self.max_asset_filename_length = int(
config.getini("max_asset_filename_length")
)
self.logfile = logfile
self.config = config
self.row_table = self.row_extra = None
@ -196,13 +205,12 @@ class HTMLReport:
def create_asset(
self, content, extra_index, test_index, file_extension, mode="w"
):
# 255 is the common max filename length on various filesystems
asset_file_name = "{}_{}_{}.{}".format(
re.sub(r"[^\w\.]", "_", self.test_id),
str(extra_index),
str(test_index),
file_extension,
)[-255:]
)[-self.max_asset_filename_length :]
asset_path = os.path.join(
os.path.dirname(self.logfile), "assets", asset_file_name
)
@ -496,7 +504,7 @@ class HTMLReport:
html.th("Result", class_="sortable result initial-sort", col="result"),
html.th("Test", class_="sortable", col="name"),
html.th("Duration", class_="sortable numeric", col="duration"),
html.th("Links"),
html.th("Links", class_="sortable links", col="links"),
]
session.config.hook.pytest_html_results_table_header(cells=cells)

View File

@ -32,6 +32,8 @@ function sort_column(elem) {
key = key_num;
} else if (elem.classList.contains('result')) {
key = key_result;
} else if (elem.classList.contains('links')) {
key = key_link;
} else {
key = key_alpha;
}
@ -178,6 +180,13 @@ function key_num(col_index) {
};
}
function key_link(col_index) {
return function(elem) {
dataCell = elem.childNodes[1].childNodes[col_index].firstChild
return dataCell == null ? "" : dataCell.innerText.toLowerCase();
};
}
function key_result(col_index) {
return function(elem) {
var strings = ['Error', 'Failed', 'Rerun', 'XFailed', 'XPassed',

View File

@ -12,7 +12,7 @@ setup(
package_data={"pytest_html": ["resources/*"]},
entry_points={"pytest11": ["html = pytest_html.plugin"]},
setup_requires=["setuptools_scm"],
install_requires=["pytest>=5.0", "pytest-metadata"],
install_requires=["pytest>=5.0,!=6.0.0", "pytest-metadata"],
license="Mozilla Public License 2.0 (MPL 2.0)",
keywords="py.test pytest html report",
python_requires=">=3.6",

View File

@ -20,7 +20,7 @@
<th class="sortable result initial-sort" col="result">Result</th>
<th class="sortable" col="name">Test</th>
<th class="sortable numeric" col="duration">Duration</th>
<th>Links</th></tr>
<th class="sortable links" col="links">Links</th></tr>
<tr hidden="true" id="not-found-message">
<th colspan="5">No results found. Try to check the filters</th>
</tr>
@ -30,7 +30,7 @@
<td class="col-result">Rerun</td>
<td class="test-1 col-name">rerun.py::test_rexample_1</td>
<td class="col-duration">1.00</td>
<td class="col-links"></td></tr>
<td class="col-links"><a class="url" href="http://www.google.com/" target="_blank">URL</a> </td></tr>
<tr>
<td class="extra" colspan="5">
<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>

View File

@ -48,6 +48,12 @@
'rerun results-table-row', 'passed results-table-row');
sort_column_test('[col=duration]',
'passed results-table-row', 'rerun results-table-row');
//links
sort_column_test('[col=links]',
'rerun results-table-row', 'passed results-table-row');
sort_column_test('[col=links]',
'passed results-table-row', 'rerun results-table-row');
});
QUnit.test('filter_table', function(assert){
@ -123,6 +129,6 @@ QUnit.test('find', function (assert) {
});
QUnit.test('find_all', function(assert) {
assert.equal(find_all('.sortable').length, 3);
assert.equal(find_all('.sortable').length, 4);
assert.equal(find_all('.not-in-table').length, 0);
});

View File

@ -566,7 +566,8 @@ class TestHTML:
assert result.ret == 0
assert '<a href="{0}"><img src="{0}"/>'.format(content) in html
def test_very_long_test_name(self, testdir):
@pytest.mark.parametrize("max_asset_filename_length", [10, 100])
def test_very_long_test_name(self, testdir, max_asset_filename_length):
testdir.makeconftest(
"""
import pytest
@ -587,8 +588,16 @@ class TestHTML:
assert False
"""
)
result, html = run(testdir)
file_name = f"test_very_long_test_name.py__{test_name}_0_0.png"[-255:]
testdir.makeini(
f"""
[pytest]
max_asset_filename_length = {max_asset_filename_length}
"""
)
result, html = run(testdir, "report.html")
file_name = f"test_very_long_test_name.py__{test_name}_0_0.png"[
-max_asset_filename_length:
]
src = "assets/" + file_name
link = f'<a class="image" href="{src}" target="_blank">'
img = f'<img src="{src}"/>'