Skip to content

Commit

Permalink
Add before suite hook to set mp start method.
Browse files Browse the repository at this point in the history
The default multiprocessing start method is "fork" which is not compatible with
with runtime assertions that it is set to spawn. When running unit tests, it's
possible to call an external library that sets the start method to "fork".
Here we enforce the start method to be "spawn" for all tests before executing.
  • Loading branch information
no0p committed Feb 28, 2025
1 parent 41e42a6 commit bed5fe8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 14 additions & 0 deletions tests/python/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import multiprocessing
import pytest


# The default multiprocessing start method is "fork" which is not compatible with
# with runtime assertions that it is set to spawn. When running unit tests, it's
# possible to call an external library that sets the start method to "fork".
# Here we enforce the start method to be "spawn" for all tests before executing.
@pytest.fixture(scope="session", autouse=True)
def initialize_data_environment():
try:
multiprocessing.set_start_method("spawn")
except Exception:
pass
6 changes: 0 additions & 6 deletions tests/python/test_code_composition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import multiprocessing
from unittest import TestCase

from dolma.core.data_types import Document
Expand Down Expand Up @@ -40,11 +39,6 @@ def baz():

class TestDolmaCodeProseCompositionClassifier(TestCase):
def setUp(self) -> None:
try:
multiprocessing.set_start_method("spawn")
except Exception:
pass

self.code_composition_tagger = CodeProseCompositionClassifier()

def test_prose_text(self):
Expand Down

0 comments on commit bed5fe8

Please sign in to comment.