You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ci_visibility): improve compatibility with external retry plugins [backport 3.10] (#13877)
Backport 775aaf0 from #13854 to 3.10.
Currently, if Test Optimization is used together with
[`pytest-rerunfailures`](https://github.com/pytest-dev/pytest-rerunfailures)
or [`flaky`](https://github.com/box/flaky), weird things happen, because
all those plugins are based on defining a custom
`pytest_runtest_protocol` hook. Depending on the plugin load order,
either the external plugins will work but ddtrace will report the test
as failed to the backend (because it did not collect the test run data),
or ddtrace will work but the external plugin will not do anything.
This PR does two things:
- Collect report information for executed tests in
`pytest_runtest_makereport` and save it into a global dictionary. This
makes the information available for us even if some other plugin runs
the test and not ours, so we can still report the test result correctly
to the backend.
- If `pytest` or `rerunfailures` is present, we let them do their thing
and don't run our `pytest_runtest_protocol`. This means our advanced
features such as EFD, ATR, and Flaky Test Management will not work, but
at least the external plugin will work correctly and we will report
their results to the backend.
### Roads not taken
I tried to overwrite the builtin pytest runner's
`pytest_runtest_protocol`, in a similar way to how [`flaky` overwrites
`call_and_report`](https://github.com/box/flaky/blob/v3.8.1/flaky/flaky_pytest_plugin.py#L87).
The problem is that then we run _inside_ `flaky`'s
`pytest_runtest_protocol`, and we end up logging and counting all
`flaky` runs, not just the last one (as should happen with `flaky`),
with the consequence that failed retries will count as failures even if
the test eventually succeeds.
Maybe one way to overcome this would be for us to wrap _`flaky`_'s
`pytest_runtest_protocol`, but I would rather avoid patching an external
plugin that patches the builtin runner. The `flaky` and `rerunfailures`
functionality largely overlaps with ATR, so it's probably a better
experience for users to use either `flaky`/`rerunfailures` or ATR, but
not both.
## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
Co-authored-by: Vítor De Araújo <[email protected]>
Co-authored-by: Brett Langdon <[email protected]>
0 commit comments