Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(ci): report decorated tests from collected files (#99865)

Paul D'Ambra28d32723832e
diff --git a/conftest.py b/conftest.py
index 0b1d02d1b4d7..33f6971ac4ef 100644
--- a/conftest.py
+++ b/conftest.py
@@ -1,9 +1,12 @@
import gc
import warnings
+from collections.abc import Generator
import pytest
import time_machine
+from posthog.test.junit import set_junit_report_location
+
# The default MIXED mode reads naive strings as local time, so a non-UTC machine would
# freeze at a different instant than CI does.
time_machine.naive_mode = time_machine.NaiveMode.UTC # ty: ignore[invalid-assignment]
@@ -220,6 +223,12 @@ def pytest_collection_finish() -> None:
_end_gc_boot_window()
[email protected](hookwrapper=True, tryfirst=True)
+def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo[None]) -> Generator[None]:
+ outcome = yield
+ set_junit_report_location(item, outcome.get_result())
+
+
@pytest.hookimpl(tryfirst=True)
def pytest_runtestloop() -> None:
# Safety net for processes that never run a local collection (e.g. the
diff --git a/posthog/test/junit.py b/posthog/test/junit.py
new file mode 100644
index 000000000000..7a180d7782e7
--- /dev/null
+++ b/posthog/test/junit.py
@@ -0,0 +1,6 @@
+import pytest
+
+
+def set_junit_report_location(item: pytest.Item, report: pytest.TestReport) -> None:
+ test_file = item.path.relative_to(item.config.rootpath).as_posix()
+ report.location = (test_file, report.location[1], report.location[2])
diff --git a/posthog/test/test_junit_report_location.py b/posthog/test/test_junit_report_location.py
new file mode 100644
index 000000000000..e13970387cfd
--- /dev/null
+++ b/posthog/test/test_junit_report_location.py
@@ -0,0 +1,26 @@
+from pathlib import Path
+from types import SimpleNamespace
+from typing import cast
+
+import pytest
+
+from posthog.test.junit import set_junit_report_location
+
+
+def test_junit_report_uses_the_collected_test_file() -> None:
+ report = pytest.TestReport(
+ nodeid="posthog/api/test/test_project.py::TestProjectAPI::test_delete_project",
+ location=("../../../../python/unittest/mock.py", 1426, "test_delete_project"),
+ keywords={},
+ outcome="passed",
+ longrepr=None,
+ when="call",
+ )
+ item = SimpleNamespace(
+ path=Path("/repo/posthog/api/test/test_project.py"),
+ config=SimpleNamespace(rootpath=Path("/repo")),
+ )
+
+ set_junit_report_location(cast(pytest.Item, item), report)
+
+ assert report.location == ("posthog/api/test/test_project.py", 1426, "test_delete_project")