11import subprocess
22import sys
3+ from functools import lru_cache
4+ from typing import Callable
5+ from typing import Iterator
36
4- import execnet
5- import py
7+ import execnet .gateway
68import pytest
79from execnet .gateway_base import get_execmodel
810from execnet .gateway_base import WorkerPool
@@ -22,10 +24,15 @@ def pytest_runtest_setup(item):
2224
2325
2426@pytest .fixture
25- def makegateway ( request ) :
27+ def group_function () -> Iterator [ execnet . Group ] :
2628 group = execnet .Group ()
27- request .addfinalizer (lambda : group .terminate (0.5 ))
28- return group .makegateway
29+ yield group
30+ group .terminate (0.5 )
31+
32+
33+ @pytest .fixture
34+ def makegateway (group_function ) -> Callable [[str ], execnet .gateway .Gateway ]:
35+ return group_function .makegateway
2936
3037
3138pytest_plugins = ["pytester" , "doctest" ]
@@ -76,7 +83,7 @@ def getspecssh(config):
7683 xspecs = getgspecs (config )
7784 for spec in xspecs :
7885 if spec .ssh :
79- if not py . path . local . sysfind ("ssh" ):
86+ if not shutil . which ("ssh" ):
8087 pytest .skip ("command not found: ssh" )
8188 return spec
8289 pytest .skip ("need '--gx ssh=...'" )
@@ -100,36 +107,18 @@ def pytest_generate_tests(metafunc):
100107 else :
101108 gwtypes = ["popen" , "socket" , "ssh" , "proxy" ]
102109 metafunc .parametrize ("gw" , gwtypes , indirect = True )
103- elif "anypython" in metafunc .fixturenames :
104- metafunc .parametrize (
105- "anypython" ,
106- indirect = True ,
107- argvalues = ("sys.executable" , "pypy3" ),
108- )
109110
110111
111- def getexecutable (name , cache = {}):
112- try :
113- return cache [name ]
114- except KeyError :
115- if name == "sys.executable" :
116- return py .path .local (sys .executable )
117- executable = py .path .local .sysfind (name )
118- if executable :
119- if name == "jython" :
120- popen = subprocess .Popen (
121- [str (executable ), "--version" ],
122- universal_newlines = True ,
123- stderr = subprocess .PIPE ,
124- )
125- out , err = popen .communicate ()
126- if not err or "2.5" not in err :
127- executable = None
128- cache [name ] = executable
129- return executable
112+ @lru_cache ()
113+ def getexecutable (name ):
114+ if name == "sys.executable" :
115+ return sys .executable
116+ import shutil
130117
118+ return shutil .which (name )
131119
132- @pytest .fixture
120+
121+ @pytest .fixture (params = ("sys.executable" , "pypy3" ))
133122def anypython (request ):
134123 name = request .param
135124 executable = getexecutable (name )
0 commit comments