Skip to content

Commit 89ca781

Browse files
pb8oManciukic
authored andcommitted
tests: prevent double publishing of metrics
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 <[email protected]>
1 parent 5b8e44a commit 89ca781

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ def record_props(request, record_property):
105105
def pytest_runtest_logreport(report):
106106
"""Send general test metrics to CloudWatch"""
107107

108+
# only publish metrics from the main process
109+
worker_id = os.environ.get("PYTEST_XDIST_WORKER")
110+
if worker_id is not None:
111+
return
112+
108113
# The pytest's test protocol has three phases for each test item: setup,
109114
# call and teardown. At the end of each phase, pytest_runtest_logreport()
110115
# is called.
@@ -135,6 +140,7 @@ def pytest_runtest_logreport(report):
135140
# and global
136141
{},
137142
)
143+
METRICS.set_property("pytest_xdist_worker", worker_id)
138144
METRICS.set_property("result", report.outcome)
139145
METRICS.set_property("location", report.location)
140146
for prop_name, prop_val in report.user_properties:

0 commit comments

Comments
 (0)