@@ -156,6 +156,23 @@ def test_foo(cov):
156156], ids = ['nodist' , 'xdist' ])
157157
158158
159+ @pytest .fixture (scope = 'session' , autouse = True )
160+ def adjust_sys_path ():
161+ """Adjust PYTHONPATH during tests to make "helper" importable in SCRIPT."""
162+ orig_path = os .environ .get ('PYTHONPATH' , None )
163+ new_path = os .path .dirname (__file__ )
164+ if orig_path is not None :
165+ new_path = os .pathsep .join ([new_path , orig_path ])
166+ os .environ ['PYTHONPATH' ] = new_path
167+
168+ yield
169+
170+ if orig_path is None :
171+ del os .environ ['PYTHONPATH' ]
172+ else :
173+ os .environ ['PYTHONPATH' ] = orig_path
174+
175+
159176@pytest .fixture (params = [
160177 ('branch=true' , '--cov-branch' , '9 * 85%' , '3 * 100%' ),
161178 ('branch=true' , '' , '9 * 85%' , '3 * 100%' ),
@@ -454,7 +471,8 @@ def test_subprocess_with_path_aliasing(testdir, monkeypatch):
454471parallel = true
455472""" )
456473
457- monkeypatch .setitem (os .environ , 'PYTHONPATH' , os .pathsep .join ([os .environ .get ('PYTHONPATH' ,'' ), 'aliased' ]))
474+ monkeypatch .setitem (os .environ , 'PYTHONPATH' , os .pathsep .join ([
475+ os .environ .get ('PYTHONPATH' , '' ), 'aliased' ]))
458476 result = testdir .runpytest ('-v' ,
459477 '--cov' ,
460478 '--cov-report=term-missing' ,
0 commit comments