Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import shutil
import signal
import tarfile
import importlib
import contextlib
from concurrent import futures
import re

Expand All @@ -11,6 +13,9 @@
from .textwrap import DALS


TIMEOUT = int(os.getenv("TIMEOUT_BACKEND_TEST", "180")) # in seconds


class BuildBackendBase:
def __init__(self, cwd='.', env={}, backend_name='setuptools.build_meta'):
self.cwd = cwd
Expand All @@ -31,10 +36,23 @@ def __getattr__(self, name):
def method(*args, **kw):
root = os.path.abspath(self.cwd)
caller = BuildBackendCaller(root, self.env, self.backend_name)
return self.pool.submit(caller, name, *args, **kw).result()
pid = None
try:
pid = self.pool.submit(os.getpid).result(TIMEOUT)
return self.pool.submit(caller, name, *args, **kw).result(TIMEOUT)
except futures.TimeoutError:
self.pool.shutdown(wait=False) # doesn't stop already running processes
self._kill(pid)
pytest.xfail(f"Backend did not respond before timeout ({TIMEOUT} s)")

return method

def _kill(self, pid):
if pid is None:
return
with contextlib.suppress(ProcessLookupError, OSError):
os.kill(pid, signal.SIGTERM if os.name == "nt" else signal.SIGKILL)


class BuildBackendCaller(BuildBackendBase):
def __init__(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ usedevelop = True
extras = testing
passenv =
SETUPTOOLS_USE_DISTUTILS
TIMEOUT_BACKEND_TEST # timeout (in seconds) for test_build_meta
windir # required for test_pkg_resources
# honor git config in pytest-perf
HOME
Expand Down