Skip to content

Commit cc80986

Browse files
authored
Implement the visible URL query parameter to control visibility of test results on page load. (#433)
* enable control of test result visability via query params * fix typos and query parsing * Add changelog entry * fix type in changelog
1 parent c9f442b commit cc80986

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Version History
99
3.2.0 (unreleased)
1010
~~~~~~~~~~~~~~~~~~
1111

12+
* Implement the ``visible`` URL query parameter to control visibility of test results on page load. (`#399 <https://github.com/pytest-dev/pytest-html/issues/399>`_)
13+
14+
* Thanks to `@TheCorp <https://github.com/TheCorp>`_ for reporting and `@gnikonorov <https://github.com/gnikonorov>`_ for the fix
15+
1216
* Make the report tab title reflect the report name. (`#412 <https://github.com/pytest-dev/pytest-html/issues/412>`_)
1317

1418
* Thanks to `@gnikonorov <https://github.com/gnikonorov>`_ for the PR

docs/user_guide.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ additional HTML and log output with a notice that the log is empty:
234234
Display options
235235
---------------
236236

237+
Auto Collapsing Table Rows
238+
~~~~~~~~~~~~~~~~~~~~~~~~~~
239+
237240
By default, all rows in the **Results** table will be expanded except those that have :code:`Passed`.
238241

239242
This behavior can be customized either with a query parameter: :code:`?collapsed=Passed,XFailed,Skipped`
@@ -246,6 +249,29 @@ or by setting the :code:`render_collapsed` in a configuration file (pytest.ini,
246249
247250
**NOTE:** Setting :code:`render_collapsed` will, unlike the query parameter, affect all statuses.
248251

252+
Controlling Test Result Visibility Via Query Params
253+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254+
255+
By default, all tests are visible, regardless of their results. It is possible to control which tests are visible on
256+
page load by passing the :code:`visible` query parameter. To use this parameter, please pass a comma separated list
257+
of test results you wish to be visible. For example, passing :code:`?visible=passed,skipped` will show only those
258+
tests in the report that have outcome :code:`passed` or :code:`skipped`.
259+
260+
Note that this match is case insensitive, so passing :code:`PASSED` and :code:`passed` has the same effect.
261+
262+
The following query parameters may be passed:
263+
264+
* :code:`passed`
265+
* :code:`skipped`
266+
* :code:`failed`
267+
* :code:`error`
268+
* :code:`xfailed`
269+
* :code:`xpassed`
270+
* :code:`rerun`
271+
272+
Formatting the Duration Column
273+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
274+
249275
The formatting of the timestamp used in the :code:`Durations` column can be modified by setting :code:`duration_formatter`
250276
on the :code:`report` attribute. All `time.strftime`_ formatting directives are supported. In addition, it is possible
251277
to supply :code:`%f` to get duration milliseconds. If this value is not set, the values in the :code:`Durations` column are

src/pytest_html/resources/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,19 @@ function hideExtras(colresultElem) {
6363
}
6464

6565
function showFilters() {
66+
let visibleString = getQueryParameter('visible') || 'all';
67+
visibleString = visibleString.toLowerCase();
68+
const checkedItems = visibleString.split(',');
69+
6670
const filterItems = document.getElementsByClassName('filter');
67-
for (let i = 0; i < filterItems.length; i++)
71+
for (let i = 0; i < filterItems.length; i++) {
6872
filterItems[i].hidden = false;
73+
74+
if (visibleString != 'all') {
75+
filterItems[i].checked = checkedItems.includes(filterItems[i].getAttribute('data-test-result'));
76+
filterTable(filterItems[i]);
77+
}
78+
}
6979
}
7080

7181
function addCollapse() {

0 commit comments

Comments
 (0)