mirror of
https://github.com/lightningd/plugins.git
synced 2026-08-13 12:33:19 +02:00
gci: Further isolate the test runs
Turns out that poetry's directory based venv was reusing the same env for all tests, making the testing far less isolated than expected.
This commit is contained in:
parent
a22a73478e
commit
48fbe6448b
1 changed files with 30 additions and 27 deletions
57
.ci/test.py
57
.ci/test.py
|
|
@ -21,13 +21,15 @@ exclude = [
|
|||
'lightning',
|
||||
'feeadjuster'
|
||||
]
|
||||
|
||||
global_dependencies = [
|
||||
'pytest',
|
||||
'pytest-xdist',
|
||||
'pytest-timeout',
|
||||
'pytest-rerunfailures',
|
||||
]
|
||||
|
||||
pip_opts = ['-qq']
|
||||
|
||||
Plugin = namedtuple(
|
||||
'Plugin',
|
||||
[
|
||||
|
|
@ -80,60 +82,61 @@ def enumerate_plugins(basedir: Path) -> Generator[Plugin, None, None]:
|
|||
def prepare_env(p: Plugin, directory: Path) -> bool:
|
||||
""" Returns whether we can run at all. Raises error if preparing failed.
|
||||
"""
|
||||
subprocess.check_call(['virtualenv', '--clear', '-q', directory])
|
||||
subprocess.check_call(['python3', '-m', 'venv', '--clear', directory])
|
||||
os.environ['PATH'] += f":{directory}"
|
||||
pip_path = directory / 'bin' / 'pip3'
|
||||
python_path = directory / 'bin' / 'python'
|
||||
|
||||
if p.framework == "pip":
|
||||
return prepare_env_pip(p, directory)
|
||||
elif p.framework == "poetry":
|
||||
return prepare_env_poetry(p)
|
||||
return prepare_env_poetry(p, directory)
|
||||
else:
|
||||
raise ValueError(f"Unknown framework {p.framework}")
|
||||
|
||||
def prepare_env_poetry(p: Plugin) -> bool:
|
||||
def prepare_env_poetry(p: Plugin, directory: Path) -> bool:
|
||||
logging.info(f"Installing a new poetry virtualenv")
|
||||
|
||||
# Ensure the root environment has a good pip, wheel and poetry
|
||||
pip3 = shutil.which('pip3')
|
||||
python3 = shutil.which('python3')
|
||||
pip3 = directory / 'bin' / 'pip3'
|
||||
poetry = directory / 'bin' / 'poetry'
|
||||
python3 = directory / 'bin' / 'python3'
|
||||
|
||||
subprocess.check_call(['which', 'python3'])
|
||||
|
||||
subprocess.check_call([
|
||||
pip3, 'install', '-U', '-qq', 'pip', 'wheel', 'poetry'
|
||||
pip3, 'install', '-U', *pip_opts, 'pip', 'wheel', 'poetry'
|
||||
], cwd=p.path.parent)
|
||||
|
||||
# Install pytest (eventually we'd want plugin authors to include
|
||||
# it in their requirements-dev.txt, but for now let's help them a
|
||||
# bit).
|
||||
subprocess.check_call(
|
||||
[pip3, 'install', '-U', '-qq', *global_dependencies],
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
|
||||
# We run all commands in the plugin directory so poetry remembers its settings
|
||||
poetry = shutil.which('poetry')
|
||||
workdir = p.path.resolve()
|
||||
|
||||
logging.info(f"Using poetry at {poetry} ({python3}) to run tests in {workdir}")
|
||||
|
||||
# Ensure that we're using the right virtualenv before installing
|
||||
try:
|
||||
#subprocess.check_call([
|
||||
# poetry_path, 'env', 'use', python3
|
||||
#], cwd=workdir)
|
||||
pass
|
||||
except:
|
||||
logging.info(f"Plugin is incompatible with the current python version, skipping")
|
||||
return False
|
||||
|
||||
# Don't let poetry create a self-managed virtualenv (paths get confusing)
|
||||
subprocess.check_call([
|
||||
poetry, 'config', 'virtualenvs.create', 'true'
|
||||
poetry, 'config', 'virtualenvs.create', 'false'
|
||||
], cwd=workdir)
|
||||
|
||||
|
||||
# Now we can proceed with the actual implementation
|
||||
logging.info(f"Installing poetry dependencies from {p.details['pyproject']}")
|
||||
logging.info(f"Installing poetry {poetry} dependencies from {p.details['pyproject']}")
|
||||
subprocess.check_call([
|
||||
poetry, 'install', '--remove-untracked'
|
||||
poetry, 'install', '--with=dev', '--no-interaction',
|
||||
], cwd=workdir)
|
||||
|
||||
subprocess.check_call([pip3, 'freeze'])
|
||||
return True
|
||||
|
||||
def prepare_env_pip(p: Plugin, directory: Path):
|
||||
pip_path = directory / 'bin' / 'pip3'
|
||||
pip_opts = ['-qq']
|
||||
|
||||
# Install pytest (eventually we'd want plugin authors to include
|
||||
# it in their requirements-dev.txt, but for now let's help them a
|
||||
|
|
@ -206,13 +209,14 @@ def run_one(p: Plugin) -> bool:
|
|||
|
||||
bin_path = vpath / 'bin'
|
||||
pytest_path = vpath / 'bin' / 'pytest'
|
||||
poetry_path = vpath / 'bin' / 'poetry'
|
||||
|
||||
pytest = [str(pytest_path)]
|
||||
if p.framework == "poetry":
|
||||
pytest = [shutil.which('poetry'), 'run', 'pytest']
|
||||
pytest = [poetry_path, 'run', 'pytest']
|
||||
|
||||
if p.framework == "poetry":
|
||||
subprocess.check_call([shutil.which('poetry'), 'env', 'info'])
|
||||
subprocess.check_call([poetry_path, 'env', 'info'])
|
||||
else:
|
||||
logging.info(f"Virtualenv at {vpath}")
|
||||
|
||||
|
|
@ -224,11 +228,10 @@ def run_one(p: Plugin) -> bool:
|
|||
'LC_ALL': 'C.UTF-8',
|
||||
'LANG': 'C.UTF-8',
|
||||
})
|
||||
cmd = pytest + [
|
||||
cmd = [str(p) for p in pytest] + [
|
||||
'-vvv',
|
||||
'--timeout=600',
|
||||
'--timeout-method=thread',
|
||||
'--reruns=2',
|
||||
'--color=yes',
|
||||
'-n=5',
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue