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

DEVINFRA-630: record "rerun" test results #86850

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ module = [
"sentry.tempest.endpoints.*",
"sentry.tempest.migrations.*",
"sentry.testutils.helpers.task_runner",
"sentry.testutils.pytest.json_report_reruns",
"sentry.testutils.skips",
"sentry.toolbar.utils.*",
"sentry.types.*",
Expand Down
1 change: 1 addition & 0 deletions src/sentry/testutils/pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
"sentry.testutils.pytest.relay",
"sentry.testutils.pytest.metrics",
"sentry.testutils.pytest.stale_database_reads",
"sentry.testutils.pytest.json_report_reruns",
]
33 changes: 33 additions & 0 deletions src/sentry/testutils/pytest/json_report_reruns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest_jsonreport.plugin # type:ignore[import-untyped]

TestItem = dict[str, list[object]]


class PytestRerunJSONReporter:
json_tests: None | dict[str, TestItem] = None

def pytest_plugin_registered(self, plugin, manager):
del manager
if isinstance(plugin, pytest_jsonreport.plugin.JSONReport):
self.json_tests = plugin._json_tests

def pytest_json_runtest_stage(self, report):
assert self.json_tests is not None

nodeid = report.nodeid
json_testitem = self.json_tests[nodeid]
if report.when in json_testitem:
# this is a new result of some kind -- record all prior data as a
# "rerun" and start over fresh
reruns = json_testitem.setdefault("reruns", [])
reruns.append(
{
key: json_testitem.pop(key)
for key in ("setup", "call", "teardown")
if key in json_testitem
}
)


def pytest_configure(config):
config.pluginmanager.register(PytestRerunJSONReporter())
Loading