E5FB Allow for redacting of environment table values by gnikonorov · Pull Request #431 · pytest-dev/pytest-html · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add documentation
  • Loading branch information
gnikonorov committed Dec 19, 2020
commit 7c2f9a47d71b9de3897d9a742f08b2164cd1b192
16 changes: 14 additions & 2 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,20 @@ Note that in the above example `@pytest.hookimpl(tryfirst=True)`_ is important,
If this line is omitted, then the *Environment* table will **not** be updated since the :code:`pytest_sessionfinish` of the plugins will execute first,
and thus not pick up your change.

The generated table will be sorted alphabetically unless the metadata is a
:code:`collections.OrderedDict`.
The generated table will be sorted alphabetically unless the metadata is a :code:`collections.OrderedDict`.

It is also possible to redact variables from the environment table. Redacted variables will have their keys displayed, but their values grayed out.
This can be achieved by setting :code:`environment_table_redact_list` in your INI configuration file (e.g.: :code:`pytest.ini`).
:code:`environment_table_redact_list` is a :code:`linelist` of regexes. Any environment table key that matches a regex in this list has its value redacted.

For example, the below will redact all environment table values whose keys match the regexes :code:`^foo$`, :code:`.*redact.*`, or :code:`bar`:

.. code-block:: ini

[pytest]
environment_table_redact_list = ^foo$
.*redact.*
bar

Additional summary information
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion testing/test_pytest_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ def test_environment_table_redact_list(self, testdir):
testdir.makeini(
"""
[pytest]
environment_table_redact_list = foo$
environment_table_redact_list = ^foo$
.*redact.*
bar
"""
Expand All @@ -1224,6 +1224,7 @@ def test_environment_table_redact_list(self, testdir):
"""
def pytest_configure(config):
config._metadata["foo"] = "will not appear a"
config._metadata["afoo"] = "will appear"
config._metadata["foos"] = "will appear"
config._metadata["redact"] = "will not appear ab"
config._metadata["will_redact"] = "will not appear abc"
Expand All @@ -1248,6 +1249,7 @@ def test_pass():
black_box_ascii_value = 0x2593
expected_environment_values = {
"foo": "".join(chr(black_box_ascii_value) for value in range(17)),
"afoo": "will appear",
"foos": "will appear",
"redact": "".join(chr(black_box_ascii_value) for value in range(18)),
"will_redact": "".join(chr(black_box_ascii_value) for value in range(19)),
Expand Down
0