@@ -49,6 +49,17 @@ def get_trace_parent(cls, config: Config) -> Optional[Context]:
49
49
50
50
return None
51
51
52
+ @classmethod
53
+ def try_force_flush (cls ) -> bool :
54
+ provider = trace .get_tracer_provider ()
55
+
56
+ # Not all providers (e.g. ProxyTraceProvider) implement force flush
57
+ if hasattr (provider , 'force_flush' ):
58
+ provider .force_flush ()
59
+ return True
60
+ else :
61
+ return False
62
+
52
63
def pytest_configure (self , config : Config ) -> None :
53
64
self .trace_parent = self .get_trace_parent (config )
54
65
@@ -75,7 +86,9 @@ def pytest_sessionfinish(self, session: Session) -> None:
75
86
self .session_span .set_status (
76
87
StatusCode .ERROR if self .has_error else StatusCode .OK
77
88
)
89
+
78
90
self .session_span .end ()
91
+ self .try_force_flush ()
79
92
80
93
@pytest .hookimpl (hookwrapper = True )
81
94
def pytest_runtest_protocol (self , item : Item ) -> Generator [None , None , None ]:
@@ -159,3 +172,6 @@ def pytest_configure(self, config: Config) -> None:
159
172
def pytest_configure_node (self , node : WorkerController ) -> None : # pragma: no cover
160
173
with trace .use_span (self .session_span , end_on_exit = False ):
161
174
propagate .inject (node .workerinput )
175
+
176
+ def pytest_xdist_node_collection_finished (node , ids ): # pragma: no cover
177
+ super ().try_force_flush ()
0 commit comments