Skip to content

Commit

Permalink
ci: add ITR unskippable marker is subprocess marker is used (#9261)
Browse files Browse the repository at this point in the history
This works around an issue where tests are improperly being skipped due
to issues collecting coverage data using coverage.py when subprocess is
used.

Whenever the subprocess marker is seen during collection, we add the
same skipif marker that's used to mark tests as unskippable, which makes
pytest run the tests no matter what.

This ends up with tests being forced to run and the
`test.itr.unskippable` tag being set to `true`:

![image](https://github.com/DataDog/dd-trace-py/assets/136473744/e189cacf-dbf5-4070-80c7-9584afe7edcc)


## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] 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)
  • Loading branch information
romainkomorndatadog authored May 17, 2024
1 parent 67741c0 commit 370b175
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ def _subprocess_wrapper():
return _subprocess_wrapper()


@pytest.hookimpl(tryfirst=True)
def pytest_collection_modifyitems(session, config, items):
"""Don't let ITR skip tests that use the subprocess marker because coverage collection in subprocesses is broken"""
for item in items:
if item.get_closest_marker("subprocess"):
if item.get_closest_marker("skipif"):
# Respect any existing skipif marker because they preempt ITR's decision-making
continue
unskippable = pytest.mark.skipif(False, reason="datadog_itr_unskippable")
item.add_marker(unskippable)


@pytest.hookimpl(tryfirst=True)
def pytest_runtest_protocol(item):
if item.get_closest_marker("skip"):
Expand Down

0 comments on commit 370b175

Please sign in to comment.