File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ import pathlib
2
+ import sys
3
+ import tempfile
1
4
import unittest .mock
2
5
from typing import List
3
6
@@ -191,6 +194,43 @@ def test_func():
191
194
control .loop_once ()
192
195
assert control .failures
193
196
197
+ def test_ignore_sys_path_hook_entry (
198
+ self , pytester : pytest .Pytester , monkeypatch : pytest .MonkeyPatch
199
+ ) -> None :
200
+ # Modifying sys.path as seen by the worker process is a bit tricky,
201
+ # because any changes made in the current process do not carry over.
202
+ # However, we can leverage the `sitecustomize` behavior to run arbitrary
203
+ # code when the subprocess interpreter is starting up. We just need to
204
+ # install our module in the search path, which we can accomplish by
205
+ # adding a temporary directory to PYTHONPATH.
206
+ tmpdir = tempfile .TemporaryDirectory ()
207
+ with open (pathlib .Path (tmpdir .name ) / "sitecustomize.py" , "w" ) as custom :
208
+ print (
209
+ textwrap .dedent (
210
+ """
211
+ import sys
212
+ sys.path.append('dummy.__path_hook__')
213
+ """
214
+ ),
215
+ file = custom ,
216
+ )
217
+
218
+ monkeypatch .setenv ("PYTHONPATH" , tmpdir .name , prepend = ":" )
219
+
220
+ item = pytester .getitem (
221
+ textwrap .dedent (
222
+ """
223
+ def test_func():
224
+ import sys
225
+ assert "dummy.__path_hook__" in sys.path
226
+ """
227
+ )
228
+ )
229
+ control = RemoteControl (item .config )
230
+ control .setup ()
231
+ topdir , failures = control .runsession ()[:2 ]
232
+ assert not failures
233
+
194
234
195
235
class TestLooponFailing :
196
236
def test_looponfail_from_fail_to_ok (self , pytester : pytest .Pytester ) -> None :
You can’t perform that action at this time.
0 commit comments