Pytest-retry

Latest version: v1.7.0

Safety actively analyzes 706267 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 3

1.4.2

Bug fixes
* Fix for issue 20: Unexpected strict xfail exception

1.4.1

**Hotfix Release**

Bug Fixes:
- Fixed a module directory which was causing an import error when attempting to retry tests.

1.4.0

**New features:**
- A new `condition` argument is available for the flaky mark which provides greater control over when tests are retried. Tests with a `condition` argument in the flaky mark will only be retried if `condition is True`. This can be used to, for example, configure a test to only retry when running on a specific operating system or during a specific time of day.

Note: There is no matching command line parameter for `condition`, but the documentation has been updated to suggest an easy workaround if you need to globally add the same condition to all of your tests at once without marking each individually.


**BREAKING CHANGES:**
Previously, any arguments not specified in a flaky mark would fall back to the default plugin values. From 1.4.0 onwards, unspecified arguments will now fall back to your _global_ defaults if specified. To understand the difference in behavior, consider the following case:

pytest-retry defaults to a value of `0` for retry delay unless specified via the command line or a flaky mark

You run the following test file

import pytest


pytest.mark.flaky(retries=3)
def test_unreliable_function():
testing some unreliable function here
assert expected function result


with the following command line arguments:


python -m pytest --retries=2, --retry-delay=5


Since the flaky mark does not specify a delay argument, prior to version 1.4.0, `test_unreliable_function` would be retried 3 times (flaky mark args override command line) with **_0_** delay between attempts. From version 1.4.0 onwards, `test_unreliable_function` would be retried 3 times with a 5 second delay between each attempt.

In other words, flaky marks before 1.4.0 silently ignore _all_ of your command line options, while flaky marks from 1.4.0 onward will respect any command line options that you did not explicitly wish to override

If you have a configuration which relies on the previous behavior and want to upgrade, it should be simple to update your affected tests accordingly. This change was made according to the principle of least surprise (the new behavior appears more intuitive), but please feel free to provide feedback on this change.


**Bug Fixes:**
Fixed a bug where 'excluded' exceptions passed to a flaky mark were not being filtered.
Fixed a test which was validating this incorrect behavior by mistake.

1.3.0

New features:

- Test retries can now be made conditional upon a list of filtered or excluded exception types. Filtered exceptions will only initiate retries if the failed test attempt occurred due to an exception in the list. Excluded exceptions will only initiate retries if the failed test attempt does not have an exception matching a listed exception.
- At a global level, this feature is implemented using two new hooks, either of which (but not both) can be defined in conftest.py.
- At a per-test level, two new arguments have been added to the flaky mark. Again, only one of these can be specified at a time.

1.2.1

Hotfix release

Fixes:
- Prevented a possible durations index error if another exception occurred during the pytest_report_teststatus stage. (e.g. if using a custom teststatus hook in conjunction with this plugin).
- Switched back to overwriting the pytest report outcome (despite its Literal typing) because otherwise the counters don't play nice.

1.2.0

New featues:

- Overhauled internal test reporting system to track outcome, attempts, and duration per test
- Instead of a boolean success key, there's now a str outcome key which can be 'passed', 'failed', or 'skipped'
- There is now a duration key (importable from the plugin) which can be used to retrieve test duration from item stashs
- Deprecated success_key

Page 2 of 3

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.