From 4454634676c12895d528a035354d3985bef34af7 Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Sun, 20 Dec 2020 00:18:07 -0500 Subject: [PATCH 1/4] enable control of test result visability via query params --- docs/user_guide.rst | 26 ++++++++++++++++++++++++++ src/pytest_html/resources/main.js | 12 +++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/user_guide.rst b/docs/user_guide.rst index 072c714c..3bf9e424 100644 --- a/docs/user_guide.rst +++ b/docs/user_guide.rst @@ -234,6 +234,9 @@ additional HTML and log output with a notice that the log is empty: Display options --------------- +Auto Collapsing Table Rows +~~~~~~~~~~~~~~~~~~~~~~~~~~ + By default, all rows in the **Results** table will be expanded except those that have :code:`Passed`. 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, **NOTE:** Setting :code:`render_collapsed` will, unlike the query parameter, affect all statuses. +Controlling Test Result Visability Via Query Params +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +By default, all tests are visible, regardless of their results. It is possible to control which tests are visible on +page load by passing the :code:`visible` query parameter. To use this parameter, please pass a comma separated list +of test results you wish to be visible. For exmaple, passing :code:`?visible=passed,skipped` will show only those +tests in the report that have outcome :code:`passed`, or :code:`skipped`. + +Note that this match is case insenstive, so passing :code:`PASSED` and :code:`passed` has the same effect. + +The following query parameters may be passed: + +* :code:`passed` +* :code:`skipped` +* :code:`failed` +* :code:`error` +* :code:`xfailed` +* :code:`xpassed` +* :code:`rerun` + +Formatting the Duration Column +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + The formatting of the timestamp used in the :code:`Durations` column can be modified by setting :code:`duration_formatter` on the :code:`report` attribute. All `time.strftime`_ formatting directives are supported. In addition, it is possible to supply :code:`%f` to get duration milliseconds. If this value is not set, the values in the :code:`Durations` column are diff --git a/src/pytest_html/resources/main.js b/src/pytest_html/resources/main.js index 3b05664a..b618258f 100644 --- a/src/pytest_html/resources/main.js +++ b/src/pytest_html/resources/main.js @@ -63,9 +63,19 @@ function hideExtras(colresultElem) { } function showFilters() { + let checked = getQueryParameter('visible') || 'all'; + checked = checked.toLowerCase(); + const filterItems = document.getElementsByClassName('filter'); - for (let i = 0; i < filterItems.length; i++) + for (let i = 0; i < filterItems.length; i++) { filterItems[i].hidden = false; + + if (checked != 'all') { + filterItems[i].checked = checked.includes(filterItems[i].getAttribute('data-test-result')); + filterTable(filterItems[i]); + } else + filterItems[i].checked = true; + } } function addCollapse() { From fd69c9ee8c19b09feb6eeefab12ebf67ff202a2c Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Sun, 20 Dec 2020 17:13:14 -0500 Subject: [PATCH 2/4] fix typos and query parsing --- docs/user_guide.rst | 8 ++++---- src/pytest_html/resources/main.js | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/user_guide.rst b/docs/user_guide.rst index 3bf9e424..5aedab57 100644 --- a/docs/user_guide.rst +++ b/docs/user_guide.rst @@ -249,15 +249,15 @@ or by setting the :code:`render_collapsed` in a configuration file (pytest.ini, **NOTE:** Setting :code:`render_collapsed` will, unlike the query parameter, affect all statuses. -Controlling Test Result Visability Via Query Params +Controlling Test Result Visibility Via Query Params ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ By default, all tests are visible, regardless of their results. It is possible to control which tests are visible on page load by passing the :code:`visible` query parameter. To use this parameter, please pass a comma separated list -of test results you wish to be visible. For exmaple, passing :code:`?visible=passed,skipped` will show only those -tests in the report that have outcome :code:`passed`, or :code:`skipped`. +of test results you wish to be visible. For example, passing :code:`?visible=passed,skipped` will show only those +tests in the report that have outcome :code:`passed` or :code:`skipped`. -Note that this match is case insenstive, so passing :code:`PASSED` and :code:`passed` has the same effect. +Note that this match is case insensitive, so passing :code:`PASSED` and :code:`passed` has the same effect. The following query parameters may be passed: diff --git a/src/pytest_html/resources/main.js b/src/pytest_html/resources/main.js index b618258f..2677eb02 100644 --- a/src/pytest_html/resources/main.js +++ b/src/pytest_html/resources/main.js @@ -63,15 +63,16 @@ function hideExtras(colresultElem) { } function showFilters() { - let checked = getQueryParameter('visible') || 'all'; - checked = checked.toLowerCase(); + let visibleString = getQueryParameter('visible') || 'all'; + visibleString = visibleString.toLowerCase(); + const checkedItems = visibleString.split(','); const filterItems = document.getElementsByClassName('filter'); for (let i = 0; i < filterItems.length; i++) { filterItems[i].hidden = false; - if (checked != 'all') { - filterItems[i].checked = checked.includes(filterItems[i].getAttribute('data-test-result')); + if (visibleString != 'all') { + filterItems[i].checked = checkedItems.includes(filterItems[i].getAttribute('data-test-result')); filterTable(filterItems[i]); } else filterItems[i].checked = true; From 0a4ba87b7c1bcdd0174f03ce8acc3962faed7ecb Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Sun, 20 Dec 2020 17:27:49 -0500 Subject: [PATCH 3/4] Add changelog entry --- docs/changelog.rst | 4 ++++ src/pytest_html/resources/main.js | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index ceeca76d..9b65468a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,6 +9,10 @@ Version History 3.2.0 (unreleased) ~~~~~~~~~~~~~~~~~~ +* Implement the ``visible`` URL query parameter to control visiblity of test results on page load. (`#399 `_) + + * Thanks to `@TheCorp `_ for reporting and `@gnikonorov `_ for the fix + * Make the report tab title reflect the report name. (`#412 `_) * Thanks to `@gnikonorov `_ for the PR diff --git a/src/pytest_html/resources/main.js b/src/pytest_html/resources/main.js index 2677eb02..a2e49d37 100644 --- a/src/pytest_html/resources/main.js +++ b/src/pytest_html/resources/main.js @@ -74,8 +74,7 @@ function showFilters() { if (visibleString != 'all') { filterItems[i].checked = checkedItems.includes(filterItems[i].getAttribute('data-test-result')); filterTable(filterItems[i]); - } else - filterItems[i].checked = true; + } } } From dc877fb9431504d3b8bcf0a0383407acc8bec3e4 Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Sun, 20 Dec 2020 17:40:20 -0500 Subject: [PATCH 4/4] fix type in changelog --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9b65468a..b9a929bf 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,7 +9,7 @@ Version History 3.2.0 (unreleased) ~~~~~~~~~~~~~~~~~~ -* Implement the ``visible`` URL query parameter to control visiblity of test results on page load. (`#399 `_) +* Implement the ``visible`` URL query parameter to control visibility of test results on page load. (`#399 `_) * Thanks to `@TheCorp `_ for reporting and `@gnikonorov `_ for the fix