Skip to content

Commit

Permalink
fix: original sort order (pytest-dev#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil authored Nov 7, 2023
1 parent e48a649 commit 4ee12c4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Versions follow `Semantic Versioning`_ (``<major>.<minor>.<patch>``).
Version History
---------------

Unreleased
~~~~~~~~~~

* Fix original initial sort INI-setting.

* Thanks to `@sturmf <https://github.com/sturmf>`_ for reporting.

4.1.0 (2023-11-04)
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion src/pytest_html/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const renderContent = (tests) => {

// remove all sorting classes and set the relevant
findAll('.sortable', tableHeader).forEach((elem) => elem.classList.remove('asc', 'desc'))
tableHeader.querySelector(`.sortable[data-column-type="${sortAttr}"]`).classList.add(sortAsc ? 'desc' : 'asc')
tableHeader.querySelector(`.sortable[data-column-type="${sortAttr}"]`)?.classList.add(sortAsc ? 'desc' : 'asc')
newTable.appendChild(tableHeader)

if (!rows.length) {
Expand Down
46 changes: 46 additions & 0 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,52 @@ def test_log_escaping(self, pytester, outcome, occurrence):
count = log.count(each)
assert_that(count).is_equal_to(occurrence)

@pytest.mark.parametrize(
"sort, order",
[
(None, ["BBB", "AAA", "CCC"]),
("result", ["BBB", "AAA", "CCC"]),
("testId", ["AAA", "BBB", "CCC"]),
("duration", ["CCC", "BBB", "AAA"]),
("original", ["AAA", "BBB", "CCC"]),
],
)
def test_initial_sort(self, pytester, sort, order):
if sort is not None:
pytester.makeini(
f"""
[pytest]
initial_sort = {sort}
"""
)

pytester.makepyfile(
"""
import pytest
from time import sleep
def test_AAA():
sleep(0.3)
assert True
def test_BBB():
sleep(0.2)
assert False
def test_CCC():
sleep(0.1)
assert True
"""
)

page = run(pytester)
assert_results(page, passed=2, failed=1)

result = page.select("td.col-testId")
assert_that(result).is_length(3)
for row, expected in zip(result, order):
assert_that(row.string).contains(expected)


class TestLogCapturing:
LOG_LINE_REGEX = r"\s+this is {}"
Expand Down

0 comments on commit 4ee12c4

Please sign in to comment.