(cls)
| 171 | |
| 172 | @classmethod |
| 173 | def find_py(cls): |
| 174 | py_exe = None |
| 175 | if sysconfig.is_python_build(): |
| 176 | py_exe = Path(sys.executable).parent / PY_EXE |
| 177 | else: |
| 178 | for p in os.getenv("PATH").split(";"): |
| 179 | if p: |
| 180 | py_exe = Path(p) / PY_EXE |
| 181 | if py_exe.is_file(): |
| 182 | break |
| 183 | else: |
| 184 | py_exe = None |
| 185 | |
| 186 | # Test launch and check version, to exclude installs of older |
| 187 | # releases when running outside of a source tree |
| 188 | if py_exe: |
| 189 | try: |
| 190 | with subprocess.Popen( |
| 191 | [py_exe, "-h"], |
| 192 | stdin=subprocess.PIPE, |
| 193 | stdout=subprocess.PIPE, |
| 194 | stderr=subprocess.PIPE, |
| 195 | encoding="ascii", |
| 196 | errors="ignore", |
| 197 | ) as p: |
| 198 | p.stdin.close() |
| 199 | version = next(p.stdout, "\n").splitlines()[0].rpartition(" ")[2] |
| 200 | p.stdout.read() |
| 201 | p.wait(10) |
| 202 | if not sys.version.startswith(version): |
| 203 | py_exe = None |
| 204 | except OSError: |
| 205 | py_exe = None |
| 206 | |
| 207 | if not py_exe: |
| 208 | raise unittest.SkipTest( |
| 209 | "cannot locate '{}' for test".format(PY_EXE) |
| 210 | ) |
| 211 | return py_exe |
| 212 | |
| 213 | def get_py_exe(self): |
| 214 | if not self.py_exe: |
no test coverage detected