The PyTest plugin enables users of the PyTestNew tab and
unittestNew tab Python test frameworks
to quarantine flaky tests and track test results. This plugin
leverages PyTest's out-of-the-box supportNew tab
for running unittest tests.
To run tests using the PyTest plugin, invoke PyTest as you ordinarily would, with the addition
of the UNFLAKABLE_API_KEY environment variable and the --enable-unflakable and --test-suite-id
command-line arguments:
In addition to the required --enable-unflakable and --test-suite-id command-line arguments,
the Unflakable PyTest plugin supports the command-line arguments below:
As an alternative to the UNFLAKABLE_API_KEY environment variable, the PyTest plugin also supports reading the API key from a file. To use this feature, omit the UNFLAKABLE_API_KEY environment variable and provide the --api-key-path command-line argument along with the path to the file containing the API key.
For security reasons, the API key itself cannot be passed as a command-line argument.
Name of the version control (e.g., Git) branch containing the code being tested.
If specified (or auto-detected when --no-git-auto-detect is omitted), this value is compared against the test suite's stable branches setting to determine whether to update the status of each test (e.g., flaky/quarantined) based on these test results, and whether to trigger notifications. Test results from unstable branches will be visible in the Unflakable web application but will not impact test statuses or trigger notifications.
Git commit hash (e.g., 8682b9e1d521a06e6b8df4eb4f0ff6ee2273f330) or other value that uniquely identifies the commit (version control revision) of the code being tested. If specified (or auto-detected when --no-git-auto-detect is omitted), this value helps identify test results in the Unflakable web application.
By default, PyTest loads all installed plugins (i.e., packages whose names begin with pytest-). Passing this argument instructs the Unflakable plugin to instrument the test run.
The maximum number of times to retry each failed test. The plugin retries each failed test until either it passes or this number of retries is exhausted. Note that the total number of attempts for each test is one greater than the number of retries, including the initial attempt.
Set this value to 0 to disable retries, which will also prevent any tests from automatically being marked as flaky.
Prevents the plugin from attempting to determine the current branch and commit hash from the GitNew tab repository containing the tests. If not using Git, or if auto-detection fails, consider providing this argument along with the optional but recommended --branch and --commit arguments.
The Python unittest test framework provides a feature for distinguishing similar tests using
subtestsNew tab.
Subtests are supported in PyTest via the
pytest-subtestsNew tab plugin. However, the
pytest-subtests plugin conflicts with the Unflakable PyTest plugin due to implementation details
concerning the reporting of test results.