Using Secrets
Secrets are values that you would like to hide in your test logs, for example, passwords, authentication keys, or even usernames, etc. In TestFlows, a secret can be defined using Secret class.
1 | Secret(name, type=None, group=None, uid=None) |
where
nameis a unique name of the secrettypesecret type (optional)groupsecret group (optional)uidsecret unique identifier (optional)
When creating a secret, only the name is required, the other arguments type,
group, uid, are optional.
The name must be a valid regex group name as defined by Python’s re module. For example, no spaces or dashes are allowed in the name, you must use underscores instead.
1 | # secret = Secret("my secret")("my secret value") # invalid, empty spaces not allowed |
If a name is invalid, you will see an exception as follows,
1 | 16ms ⟥ Exception: Traceback (most recent call last): |
Here is an example of how to create and use secrets,
1 | from testflows.core import * |
1 | Mar 03,2022 11:22:01 ⟥ Scenario using secrets |
Secret values are only filtered by TestFlows in messages added to the test by message() function, note() function, debug() function, trace() function and messages in results.
If you need to create multiple secrets, the names of each secret must be unique otherwise, you will get an error.
1 | Mar 24,2022 9:54:46 ⟥ Scenario using secrets |
Here is an example of creating multiple secrets,
1 | with Scenario("using secrets"): |
Note, that multiple secrets can have the same secret value. For example,
1 | with Scenario("using secrets"): |
Secrets in Argument Parser
You can easily use secrets in the Argument Parser by setting type of
the argument to the Secret class object.
For example,
1 | def argparser(parser): |