Skip to content

Commit 59f47f9

Browse files
committed
Move netfx tests to individual subprocesses
1 parent 05235b9 commit 59f47f9

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

tests/test_common.py

+22-31
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,15 @@ def test_coreclr(example_netcore: Path):
7676

7777

7878
def test_coreclr_properties(example_netcore: Path):
79-
from multiprocessing import get_context
80-
81-
p = get_context("spawn").Process(
82-
target=_do_test_coreclr_autogenerated_runtimeconfig,
83-
args=(example_netstandard,),
84-
kwargs=dict(properties=dict(APP_CONTEXT_BASE_DIRECTORY=str(example_netcore))),
79+
run_in_subprocess(
80+
_do_test_coreclr_autogenerated_runtimeconfig,
81+
example_netstandard,
82+
properties=dict(APP_CONTEXT_BASE_DIRECTORY=str(example_netcore)),
8583
)
86-
p.start()
87-
p.join()
88-
p.close()
8984

9085

9186
def test_coreclr_autogenerated_runtimeconfig(example_netstandard: Path):
92-
from multiprocessing import get_context
93-
94-
p = get_context("spawn").Process(
95-
target=_do_test_coreclr_autogenerated_runtimeconfig, args=(example_netstandard,)
96-
)
97-
p.start()
98-
p.join()
99-
p.close()
87+
run_in_subprocess(_do_test_coreclr_autogenerated_runtimeconfig, example_netstandard)
10088

10189

10290
def _do_test_coreclr_autogenerated_runtimeconfig(
@@ -114,37 +102,31 @@ def _do_test_coreclr_autogenerated_runtimeconfig(
114102
sys.platform != "win32", reason=".NET Framework only exists on Windows"
115103
)
116104
def test_netfx(example_netstandard: Path):
117-
from clr_loader import get_netfx
118-
119-
netfx = get_netfx()
120-
asm = netfx.get_assembly(example_netstandard / "example.dll")
121-
122-
run_tests(asm)
105+
run_in_subprocess(_do_test_netfx, example_netstandard)
123106

124107

125108
@pytest.mark.skipif(
126109
sys.platform != "win32", reason=".NET Framework only exists on Windows"
127110
)
128111
def test_netfx_chinese_path(example_netstandard: Path, tmpdir_factory):
129-
from clr_loader import get_netfx
130-
131112
tmp_path = Path(tmpdir_factory.mktemp("example-中国"))
132113
shutil.copytree(example_netstandard, tmp_path, dirs_exist_ok=True)
133114

134-
netfx = get_netfx()
135-
asm = netfx.get_assembly(os.path.join(example_netstandard, "example.dll"))
136-
137-
run_tests(asm)
115+
run_in_subprocess(_do_test_netfx, tmp_path)
138116

139117

140118
@pytest.mark.skipif(
141119
sys.platform != "win32", reason=".NET Framework only exists on Windows"
142120
)
143121
def test_netfx_separate_domain(example_netstandard):
122+
run_in_subprocess(_do_test_netfx, example_netstandard, domain="some domain")
123+
124+
125+
def _do_test_netfx(example_netstandard, **kwargs):
144126
from clr_loader import get_netfx
145127

146-
netfx = get_netfx(domain="some_domain")
147-
asm = netfx.get_assembly(os.path.join(example_netstandard, "example.dll"))
128+
netfx = get_netfx(**kwargs)
129+
asm = netfx.get_assembly(example_netstandard / "example.dll")
148130

149131
run_tests(asm)
150132

@@ -154,3 +136,12 @@ def run_tests(asm):
154136
test_data = b"testy mctestface"
155137
res = func(test_data)
156138
assert res == len(test_data)
139+
140+
141+
def run_in_subprocess(func, *args, **kwargs):
142+
from multiprocessing import get_context
143+
144+
p = get_context("spawn").Process(target=func, args=args, kwargs=kwargs)
145+
p.start()
146+
p.join()
147+
p.close()

0 commit comments

Comments
 (0)