Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting by custom columns no longer works #782

Open
headtr1ck opened this issue Dec 7, 2023 · 3 comments
Open

Sorting by custom columns no longer works #782

headtr1ck opened this issue Dec 7, 2023 · 3 comments

Comments

@headtr1ck
Copy link

With the update to 4.1.1 the sorting of our custom columns stopped working.

First of all, the "sorting" only happens when I click on the header twice (which is not a hard requirement by us).
Second, the sorting does not work at all.
Our values in one row are e.g. ["CKD ATBD 6.2", "L1 ATBD 5.1", "CKD ATBD 8.1", "CKD ATBD 4.7"], this is already the output of the sorting. Interestingly the descending sorting keeps this wrong ordering in reverse. We have also tried this with only the numerical values, same result.
Another column simply contains short words separated by spaces, and the ordering is also broken there.

The header is modified the following way

def pytest_html_results_table_header(cells):
    cells.insert(
        1, '<th class="sortable keydata" data-column-type="keydata">Key Data</th>'
    )
    cells.insert(1, '<th class="sortable ref" data-column-type="ref">Reference</th>')
    # remove links column
    cells.pop()

And the cells are added:

def pytest_html_results_table_row(report, cells):
    ref = "CKD ATBD 5.1"  # extracted from report in actual code
    key = "Fancy"  # extracted from report in actual code
    cells.insert(1, f"<td>{ref}</td>")
    cells.insert(1, f"<td>{key}</td>")
    # Remove links column
    cells.pop()

Here is our environment.


Python | 3.9.10
Packages | pytest: 7.4.3 pluggy: 1.0.0
Plugins | sugar: 0.9.7 html: 4.1.1 xdist: 3.5.0 metadata: 3.0.0 cov: 4.1.0 anyio: 3.7.0

@BeyondEvil
Copy link
Contributor

Does it work with previous 4.x versions?

@BeyondEvil
Copy link
Contributor

According to the documentation. The row td's need a class name that matches the data-column-type. So in your case, this should solved it:

def pytest_html_results_table_row(report, cells):
    ref = "CKD ATBD 5.1"  # extracted from report in actual code
    key = "Fancy"  # extracted from report in actual code
    cells.insert(1, f"<td class=\"col-ref\">{ref}</td>")
    cells.insert(1, f"<td class=\"col-keydata\">{key}</td>")
    # Remove links column
    cells.pop()

@headtr1ck
Copy link
Author

Thanks! That fixes it.
I thought that this was just a css class for styling.
Good to know that it needs to be exactly this format (col-{data-column-type}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants