Skip to content

Commit ecae68d

Browse files
fix(ci_visibility): fix adding test.skipped_by_itr tag [backport 1.20] (#7303)
Backport 370f7da from #7275 to 1.20. Fixes an issue where tests skipped by the Intelligent Test Runner were not properly getting the `test.skipped_by_itr` tag (due to an invalid comparison between a Pytest reason object and a string). No release note because ITR is still in beta. ## 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] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [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)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly 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) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. Co-authored-by: Romain Komorn <[email protected]>
1 parent b4f8203 commit ecae68d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

ddtrace/contrib/pytest/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,11 @@ def pytest_runtest_makereport(item, call):
759759
reason = _extract_reason(call)
760760
if reason is not None:
761761
span.set_tag_str(test.SKIP_REASON, str(reason))
762-
if reason == SKIPPED_BY_ITR_REASON:
762+
if str(reason) == SKIPPED_BY_ITR_REASON:
763+
if _CIVisibility._instance._suite_skipping_mode:
764+
suite_span = _extract_span(item.parent)
765+
if suite_span is not None:
766+
suite_span.set_tag_str(test.ITR_SKIPPED, "true")
763767
span.set_tag_str(test.ITR_SKIPPED, "true")
764768
elif result.passed:
765769
_mark_not_skipped(item.parent)

tests/contrib/pytest/test_pytest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,16 @@ def test_pytest_skip_suite_by_path(self):
18401840
skipped_spans = [x for x in spans if x.get_tag("test.status") == "skip"]
18411841
assert len(skipped_spans) == 3
18421842

1843+
skipped_suite_spans = [x for x in skipped_spans if x.get_tag("type") == "test_suite_end"]
1844+
assert len(skipped_suite_spans) == 1
1845+
for skipped_suite_span in skipped_suite_spans:
1846+
assert skipped_suite_span.get_tag("test.skipped_by_itr") == "true"
1847+
1848+
skipped_test_spans = [x for x in skipped_spans if x.get_tag("type") == "test"]
1849+
assert len(skipped_test_spans) == 1
1850+
for skipped_test_span in skipped_test_spans:
1851+
assert skipped_test_span.get_tag("test.skipped_by_itr") == "true"
1852+
18431853
def test_pytest_skip_tests_by_path(self):
18441854
"""
18451855
Test that running pytest on two nested packages with 1 test each. It should generate
@@ -1909,6 +1919,10 @@ def test_pytest_skip_tests_by_path(self):
19091919
skipped_spans = [x for x in spans if x.get_tag("test.status") == "skip"]
19101920
assert len(skipped_spans) == 3
19111921

1922+
skipped_test_spans = [x for x in skipped_spans if x.get_tag("type") == "test"]
1923+
for skipped_test_span in skipped_test_spans:
1924+
assert skipped_test_span.get_tag("test.skipped_by_itr") == "true"
1925+
19121926
def test_pytest_skip_none_tests(self):
19131927
"""
19141928
Test that running pytest on two nested packages with 1 test each. It should generate
@@ -2016,6 +2030,11 @@ def test_pytest_skip_all_tests(self):
20162030
skipped_spans = [x for x in spans if x.get_tag("test.status") == "skip"]
20172031
assert len(skipped_spans) == 7
20182032

2033+
skipped_test_spans = [x for x in skipped_spans if x.get_tag("type") == "test"]
2034+
assert len(skipped_test_spans) == 2
2035+
for skipped_test_span in skipped_test_spans:
2036+
assert skipped_test_span.get_tag("test.skipped_by_itr") == "true"
2037+
20192038
def test_pytest_skip_all_test_suites(self):
20202039
"""
20212040
Test that running pytest on two nested packages with 1 test each. It should generate
@@ -2069,6 +2088,18 @@ def test_pytest_skip_all_test_suites(self):
20692088
skipped_spans = [x for x in spans if x.get_tag("test.status") == "skip"]
20702089
assert len(skipped_spans) == 7
20712090

2091+
skipped_suite_spans = [
2092+
x for x in spans if x.get_tag("test.status") == "skip" and x.get_tag("type") == "test_suite_end"
2093+
]
2094+
assert len(skipped_suite_spans) == 2
2095+
for skipped_suite_span in skipped_suite_spans:
2096+
assert skipped_suite_span.get_tag("test.skipped_by_itr") == "true"
2097+
2098+
skipped_test_spans = [x for x in spans if x.get_tag("test.status") == "skip" and x.get_tag("type") == "test"]
2099+
assert len(skipped_test_spans) == 2
2100+
for skipped_test_span in skipped_test_spans:
2101+
assert skipped_test_span.get_tag("test.skipped_by_itr") == "true"
2102+
20722103
def test_pytest_skip_none_test_suites(self):
20732104
"""
20742105
Test that running pytest on two nested packages with 1 test each. It should generate

0 commit comments

Comments
 (0)