Fix: Support cells.pop() (#641)

This commit is contained in:
Jim Brännlund 2023-04-09 00:35:06 +02:00 committed by GitHub
parent 43175f1b1a
commit 412f01bc7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 23 deletions

View File

@ -12,7 +12,7 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != github.event.repository.default_branch }}
cancel-in-progress: ${{ ! contains(github.ref, github.event.repository.default_branch) }}
jobs:
build_docs:

View File

@ -246,8 +246,8 @@ class BaseReport:
header_cells = Header()
session.config.hook.pytest_html_results_table_header(cells=header_cells)
self._report.set_data("resultsTableHeader", header_cells.html)
self._report.set_data("headerPops", header_cells.get_pops())
self._report.set_data("runningState", "Started")
self._generate_report()

View File

@ -44,6 +44,19 @@ const renderContent = (tests) => {
table.querySelectorAll('.extra').forEach((item) => {
item.colSpan = document.querySelectorAll('th').length
})
const { headerPops } = manager.renderData
if (headerPops > 0) {
// remove 'headerPops' number of header columns
findAll('#results-table-head th').splice(-headerPops).forEach(column => column.remove())
// remove 'headerPops' number of row columns
const resultRows = findAll('.results-table-row')
resultRows.forEach((elem) => {
findAll('td:not(.extra)', elem).splice(-headerPops).forEach(column => column.remove())
})
}
findAll('.sortable').forEach((elem) => {
elem.addEventListener('click', (evt) => {
const { target: element } = evt

View File

@ -29,7 +29,6 @@ const doInitSort = () => {
const ascending = storageModule.getSortDirection()
const list = manager.testSubset
const initialOrder = ['Error', 'Failed', 'Rerun', 'XFailed', 'XPassed', 'Skipped', 'Passed']
console.log(list)
if (type?.toLowerCase() === 'original') {
manager.setRender(list)
} else {

View File

@ -33,6 +33,7 @@ class Cell(Table):
def __init__(self):
super().__init__()
self._append_counter = 0
self._pop_counter = 0
self._sortables = dict()
def __setitem__(self, key, value):
@ -69,10 +70,10 @@ class Cell(Table):
self._html[index] = html
def pop(self, *args):
warnings.warn(
"'pop' is deprecated and no longer supported.",
DeprecationWarning,
)
self._pop_counter += 1
def get_pops(self):
return self._pop_counter
def _extract_sortable(self, html):
match = re.search(r'<td class="col-(\w+)">(.*?)</', html)
@ -90,3 +91,7 @@ class Row(Cell):
def __delitem__(self, key):
# This means the item should be removed
self._html = None
def pop(self, *args):
# Calling pop on header is sufficient
pass

View File

@ -690,6 +690,27 @@ class TestHTML:
page = run(pytester)
assert_results(page, passed=1)
def test_results_table_hook_pop(self, pytester):
pytester.makeconftest(
"""
def pytest_html_results_table_header(cells):
cells.pop()
def pytest_html_results_table_row(report, cells):
cells.pop()
"""
)
pytester.makepyfile("def test_pass(): pass")
page = run(pytester)
header_columns = page.select(".summary #results-table-head th")
assert_that(header_columns).is_length(3)
row_columns = page.select_one(".summary .results-table-row").select(
"td:not(.extra)"
)
assert_that(row_columns).is_length(3)
@pytest.mark.parametrize("no_capture", ["", "-s"])
def test_standard_streams(self, pytester, no_capture):
pytester.makepyfile(

View File

@ -24,19 +24,3 @@ def test_duration_format_deprecation_warning(pytester):
"*DeprecationWarning: 'duration_formatter'*",
],
)
def test_cells_pop_deprecation_warning(pytester):
pytester.makeconftest(
"""
def pytest_html_results_table_row(cells):
cells.pop()
"""
)
pytester.makepyfile("def test_pass(): pass")
result = run(pytester)
result.stdout.fnmatch_lines(
[
"*DeprecationWarning: 'pop' is deprecated*",
],
)