shunping commented on code in PR #38498:
URL: https://github.com/apache/beam/pull/38498#discussion_r3241362130


##########
sdks/python/apache_beam/utils/multi_process_shared_test.py:
##########
@@ -23,11 +23,31 @@
 import threading
 import unittest
 from typing import Any
+
+import pytest
 from unittest.mock import patch
 
 from apache_beam.utils import multi_process_shared
 
 
[email protected](autouse=True)
+def isolate_multi_process_shared_tests(tmp_path, monkeypatch):
+  """Isolates MultiProcessShared tests by using a unique temp directory per 
test.
+
+  This prevents tests running in parallel (e.g. with pytest-xdist) from
+  interfering with each other by writing to the same shared default temp 
directory.
+  """
+  orig_init = multi_process_shared.MultiProcessShared.__init__
+
+  def mock_init(self, constructor, tag, *args, **kwargs):
+    if 'path' not in kwargs:
+      kwargs['path'] = str(tmp_path)
+    return orig_init(self, constructor, tag, *args, **kwargs)

Review Comment:
   path is keyword-only argument in the original init, no need to change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to