@@ -76,27 +76,15 @@ def test_coreclr(example_netcore: Path):
7676
7777
7878def 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
9186def 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
10290def _do_test_coreclr_autogenerated_runtimeconfig (
@@ -114,25 +102,31 @@ def _do_test_coreclr_autogenerated_runtimeconfig(
114102 sys .platform != "win32" , reason = ".NET Framework only exists on Windows"
115103)
116104def 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)
128111def 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" ))
115+ run_in_subprocess (_do_test_netfx , tmp_path )
116+
117+
118+ @pytest .mark .skipif (
119+ sys .platform != "win32" , reason = ".NET Framework only exists on Windows"
120+ )
121+ 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 ):
126+ from clr_loader import get_netfx
127+
128+ netfx = get_netfx (** kwargs )
129+ asm = netfx .get_assembly (example_netstandard / "example.dll" )
136130
137131 run_tests (asm )
138132
@@ -142,3 +136,12 @@ def run_tests(asm):
142136 test_data = b"testy mctestface"
143137 res = func (test_data )
144138 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