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

test: return spans as dict #34

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: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def set_api_url(
monkeypatch.setenv("MERGIFY_API_URL", "http://localhost:9999")


PytesterWithSpanReturnT = tuple[_pytest.pytester.RunResult, list[trace.ReadableSpan]]
PytesterWithSpanReturnT = tuple[
_pytest.pytester.RunResult, dict[str, trace.ReadableSpan]
]


class PytesterWithSpanT(typing.Protocol):
Expand Down Expand Up @@ -45,6 +47,9 @@ def _run(
spans: list[trace.ReadableSpan] = (
plugin.mergify_tracer.exporter.get_finished_spans() # type: ignore[attr-defined]
)
return result, spans
spans_as_dict = {s.name: s for s in spans}
# Make sure we don't lose spans in the process
assert len(spans_as_dict) == len(spans)
return result, spans_as_dict

return _run
10 changes: 5 additions & 5 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_span_resources_attributes_ci(
result, spans = pytester_with_spans()
assert all(
span.resource.attributes["cicd.provider.name"] == utils.get_ci_provider()
for span in spans
for span in spans.values()
)


Expand All @@ -28,7 +28,7 @@ def test_span_resources_attributes_pytest(
r"\d\.",
typing.cast(str, span.resource.attributes["test.framework.version"]),
)
for span in spans
for span in spans.values()
)


Expand All @@ -40,7 +40,7 @@ def test_span_github_actions(
monkeypatch.setenv("GITHUB_ACTIONS", "true")
monkeypatch.setenv("GITHUB_REPOSITORY", "Mergifyio/pytest-mergify")
result, spans = pytester_with_spans()
assert (
spans[0].resource.attributes["vcs.repository.name"]
== "Mergifyio/pytest-mergify"
assert all(
span.resource.attributes["vcs.repository.name"] == "Mergifyio/pytest-mergify"
for span in spans.values()
)
12 changes: 7 additions & 5 deletions tests/test_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ def test_span(
pytester_with_spans: conftest.PytesterWithSpanT,
) -> None:
result, spans = pytester_with_spans()
assert any(s.name == "test run" for s in spans)
assert any(s.name == "test_span.py::test_pass" for s in spans)
assert any(s.name == "test_span.py::test_pass::setup" for s in spans)
assert any(s.name == "test_span.py::test_pass::call" for s in spans)
assert any(s.name == "test_span.py::test_pass::teardown" for s in spans)
assert set(spans.keys()) == {
"test run",
"test_span.py::test_pass",
"test_span.py::test_pass::setup",
"test_span.py::test_pass::call",
"test_span.py::test_pass::teardown",
}