From 89ca78177ba4ee5faeb225d2ff16641e82da2b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Barb=C3=A1chano?= Date: Thu, 12 Dec 2024 17:39:05 +0100 Subject: [PATCH] tests: prevent double publishing of metrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seem that pytest_runtest_logreport is triggered for the worker where the test happens and the main process. So do not emit metrics unless we are in the main process. Signed-off-by: Pablo Barbáchano --- tests/conftest.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index ac73b4bd8ab..865fa0b44b2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -105,6 +105,11 @@ def record_props(request, record_property): def pytest_runtest_logreport(report): """Send general test metrics to CloudWatch""" + # only publish metrics from the main process + worker_id = os.environ.get("PYTEST_XDIST_WORKER") + if worker_id is not None: + return + # The pytest's test protocol has three phases for each test item: setup, # call and teardown. At the end of each phase, pytest_runtest_logreport() # is called. @@ -135,6 +140,7 @@ def pytest_runtest_logreport(report): # and global {}, ) + METRICS.set_property("pytest_xdist_worker", worker_id) METRICS.set_property("result", report.outcome) METRICS.set_property("location", report.location) for prop_name, prop_val in report.user_properties: