Repository navigation
Sort numeric values in sortable columns numerically - #1083
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
Sortable columns other than result and duration were always compared as strings, so custom columns holding numbers (e.g. a "speedup" column added through pytest_html_results_table_header/row) were ordered lexicographically: "10.5" came before "9.25". Compare two values numerically when both are numbers, and keep the existing string comparison otherwise. When a column mixes numeric and non-numeric values, numbers are placed before the rest so the comparison stays a consistent total order. Add a JavaScript unit test and an end-to-end test for sorting a custom numeric column, and mention numeric sorting in the user guide. Fixes pytest-dev#818
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sortable columns other than Result and Duration were always compared as strings. Custom columns holding numbers (e.g. a
speedupcolumn added throughpytest_html_results_table_header/pytest_html_results_table_row) were therefore sorted lexicographically:10.5came before9.25.Changes
genericSortnow uses acompareValueshelper. When both values are numbers it compares them numerically; otherwise it keeps the existing string comparison.n/a), numbers go before the rest. This keeps the comparator a consistent total order instead of mixing numeric and string comparisons.0.Testing
sort on numeric columnintesting/unittest.js.test_custom_numeric_sortingintesting/test_e2e.py: sorts a custom numeric column through thesortquery parameter and then by clicking the header.Both tests fail on
masterand pass with this change.npm run lintandnpm run unitpass.Fixes #818