Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test.case.result.status #55

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pytest_mergify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,14 @@ def pytest_runtest_logreport(self, report: _pytest.reports.TestReport) -> None:
else opentelemetry.trace.StatusCode.OK
)
self.has_error |= has_error
opentelemetry.trace.get_current_span().set_status(status_code)

test_span = opentelemetry.trace.get_current_span()
test_span.set_status(status_code)
test_span.set_attributes(
{
"test.case.result.status": report.outcome,
}
)


def pytest_addoption(parser: _pytest.config.argparsing.Parser) -> None:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_test(
"code.lineno": 0,
"code.filepath": "test_test.py",
"test.case.name": "test_test.py::test_pass",
"test.case.result.status": "passed",
}
assert (
spans["test_test.py::test_pass"].status.status_code
Expand All @@ -67,6 +68,7 @@ def test_test_failure(
session_span = spans["pytest session start"]

assert spans["test_test_failure.py::test_error"].attributes == {
"test.case.result.status": "failed",
"test.type": "case",
"code.function": "test_error",
"code.lineno": 0,
Expand Down Expand Up @@ -96,6 +98,36 @@ def test_test_failure(
)


def test_test_skipped(
pytester_with_spans: conftest.PytesterWithSpanT,
) -> None:
result, spans = pytester_with_spans("""
import pytest
def test_skipped():
pytest.skip('not needed')
""")
session_span = spans["pytest session start"]

assert spans["test_test_skipped.py::test_skipped"].attributes == {
"test.case.result.status": "skipped",
"test.type": "case",
"code.function": "test_skipped",
"code.lineno": 1,
"code.filepath": "test_test_skipped.py",
"test.case.name": "test_test_skipped.py::test_skipped",
}
assert (
spans["test_test_skipped.py::test_skipped"].status.status_code
== opentelemetry.trace.StatusCode.OK
)
assert session_span.context is not None
assert spans["test_test_skipped.py::test_skipped"].parent is not None
assert (
spans["test_test_skipped.py::test_skipped"].parent.span_id
== session_span.context.span_id
)


def test_fixture(
pytester_with_spans: conftest.PytesterWithSpanT,
) -> None:
Expand Down