|
1 | 1 | import opentelemetry.trace |
2 | 2 | from opentelemetry.semconv.trace import SpanAttributes |
3 | 3 |
|
| 4 | +import pytest |
4 | 5 |
|
5 | 6 | from tests import conftest |
6 | 7 |
|
@@ -107,6 +108,69 @@ def test_skipped(): |
107 | 108 | assert spans["test_skipped"].parent.span_id == session_span.context.span_id |
108 | 109 |
|
109 | 110 |
|
| 111 | +@pytest.mark.parametrize( |
| 112 | + "mark", |
| 113 | + [ |
| 114 | + "skip", |
| 115 | + "skipif(True, reason='not needed')", |
| 116 | + "skipif(1 + 1, reason='with eval')", |
| 117 | + "skipif('1 + 1', reason='as str')", |
| 118 | + ], |
| 119 | +) |
| 120 | +def test_mark_skipped( |
| 121 | + mark: str, |
| 122 | + pytester_with_spans: conftest.PytesterWithSpanT, |
| 123 | +) -> None: |
| 124 | + result, spans = pytester_with_spans(f""" |
| 125 | +import pytest |
| 126 | +@pytest.mark.{mark} |
| 127 | +def test_skipped(): |
| 128 | + assert False |
| 129 | +""") |
| 130 | + session_span = spans["pytest session start"] |
| 131 | + |
| 132 | + assert spans["test_skipped"].attributes == { |
| 133 | + "test.case.result.status": "skipped", |
| 134 | + "test.scope": "case", |
| 135 | + "code.function": "test_skipped", |
| 136 | + "code.lineno": 1, |
| 137 | + "code.filepath": "test_mark_skipped.py", |
| 138 | + } |
| 139 | + assert ( |
| 140 | + spans["test_skipped"].status.status_code == opentelemetry.trace.StatusCode.UNSET |
| 141 | + ) |
| 142 | + assert session_span.context is not None |
| 143 | + assert spans["test_skipped"].parent is not None |
| 144 | + assert spans["test_skipped"].parent.span_id == session_span.context.span_id |
| 145 | + |
| 146 | + |
| 147 | +def test_mark_not_skipped( |
| 148 | + pytester_with_spans: conftest.PytesterWithSpanT, |
| 149 | +) -> None: |
| 150 | + result, spans = pytester_with_spans(""" |
| 151 | +import pytest |
| 152 | +@pytest.mark.skipif(False, reason='not skipped') |
| 153 | +def test_not_skipped(): |
| 154 | + assert True |
| 155 | +""") |
| 156 | + session_span = spans["pytest session start"] |
| 157 | + |
| 158 | + assert spans["test_not_skipped"].attributes == { |
| 159 | + "test.case.result.status": "passed", |
| 160 | + "test.scope": "case", |
| 161 | + "code.function": "test_not_skipped", |
| 162 | + "code.lineno": 1, |
| 163 | + "code.filepath": "test_mark_not_skipped.py", |
| 164 | + } |
| 165 | + assert ( |
| 166 | + spans["test_not_skipped"].status.status_code |
| 167 | + == opentelemetry.trace.StatusCode.OK |
| 168 | + ) |
| 169 | + assert session_span.context is not None |
| 170 | + assert spans["test_not_skipped"].parent is not None |
| 171 | + assert spans["test_not_skipped"].parent.span_id == session_span.context.span_id |
| 172 | + |
| 173 | + |
110 | 174 | def test_span_resources_test_run_id( |
111 | 175 | pytester_with_spans: conftest.PytesterWithSpanT, |
112 | 176 | ) -> None: |
|
0 commit comments