Skip to content

Commit 21d6e3f

Browse files
committed
Sort tests by order collected by pytest
1 parent 41251ae commit 21d6e3f

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

pytest_mpl/summary/html.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ def get_status(item, card_id, warn_missing):
113113
return status, classes, badge
114114

115115

116-
def card(name, item, warn_missing=None):
117-
card_id = name.replace('.', '-')
116+
def card(name, item, card_id, warn_missing=None):
118117
test_name = name.split('.')[-1]
119118
module = '.'.join(name.split('.')[:-1])
120119

@@ -203,9 +202,11 @@ def generate_summary_html(results, results_dir):
203202
classes += ['no-hash-test']
204203

205204
# Generate result cards
205+
pad = len(str(len(results.items())))
206206
cards = []
207-
for name, item in results.items():
208-
cards += [card(name, item, warn_missing=warn_missing)]
207+
for collect_n, (name, item) in enumerate(results.items()):
208+
card_id = str(collect_n).zfill(pad) # zero pad for alphanumerical sorting
209+
cards += [card(name, item, card_id, warn_missing=warn_missing)]
209210
cards = [j[0] for j in sorted(cards, key=lambda i: i[1], reverse=True)]
210211

211212
# Generate HTML

pytest_mpl/summary/templates/extra.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
1313

1414
// Search, sort and filter
1515
var options = {
16-
valueNames: ['test-name', 'status-sort', 'rms-sort', 'filter-classes',
16+
valueNames: ['collected-sort', 'test-name', 'status-sort', 'rms-sort', 'filter-classes',
1717
'rms-value', 'baseline-hash-value', 'result-hash-value']
1818
};
1919
var resultsList = new List('results', options);

pytest_mpl/summary/templates/filter.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ <h5>Sort tests by...</h5>
1010
id="sortstatus"
1111
autocomplete="off" checked>
1212
<label class="btn btn-outline-secondary" for="sortstatus">status</label>
13+
<input type="radio" class="btn-check sort" data-sort="collected-sort" data-order="asc" name="sort"
14+
id="sortcollected" autocomplete="off">
15+
<label class="btn btn-outline-secondary" for="sortcollected">collected</label>
1316
<input type="radio" class="btn-check sort" data-sort="test-name" name="sort" id="sortname"
1417
autocomplete="off">
1518
<label class="btn btn-outline-secondary" for="sortname">name</label>

pytest_mpl/summary/templates/result.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div class="py-2 col-sm-6 col-lg-4 col-xxl-3 result {classes}">
2+
<span class="collected-sort" style="display:none">{id}</span>
23
<span class="test-name" style="display:none">{module}.{test_name}</span>
34
<span class="status-sort" style="display:none">{status_sort}</span>
45
<span class="rms-sort" style="display:none">{rms_sort}</span>

0 commit comments

Comments
 (0)