forked from Mirror/pmbootstrap
test: conftest: require_programs() automatically (MR 2483)
Pmbootstrap finds all its host dependencies during init, ensure we do that for pytest too. Adapt require_programs() to use subprocess directly rather than have to solve the weird dependency chain of pmb.helpers.run which depends on the global context being initialised before it's usable. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
cefe98fb69
commit
bb12609753
3 changed files with 17 additions and 4 deletions
|
@ -33,7 +33,7 @@ codespell:
|
||||||
pytest:
|
pytest:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- "apk -q add git android-tools"
|
- "apk -q add git android-tools multipath-tools losetup"
|
||||||
- "su build -c 'git config --global user.email ci@ci'"
|
- "su build -c 'git config --global user.email ci@ci'"
|
||||||
- "su build -c 'git config --global user.name CI'"
|
- "su build -c 'git config --global user.name CI'"
|
||||||
- "echo 'build ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
|
- "echo 'build ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
|
||||||
|
|
|
@ -32,6 +32,7 @@ import pmb.chroot.zap
|
||||||
import pmb.parse.deviceinfo
|
import pmb.parse.deviceinfo
|
||||||
from pmb.parse.deviceinfo import Deviceinfo
|
from pmb.parse.deviceinfo import Deviceinfo
|
||||||
import pmb.parse._apkbuild
|
import pmb.parse._apkbuild
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def require_programs() -> None:
|
def require_programs() -> None:
|
||||||
|
@ -50,11 +51,16 @@ def require_programs() -> None:
|
||||||
if "losetup" not in missing:
|
if "losetup" not in missing:
|
||||||
# Check if losetup supports the --json argument. Use the absolute path
|
# Check if losetup supports the --json argument. Use the absolute path
|
||||||
# here, so it works in Debian too without using sudo.
|
# here, so it works in Debian too without using sudo.
|
||||||
|
# FIXME: we use subprocess directly here since pmb.helpers.run.user() requires
|
||||||
|
# global context to be initialized but we want this to run early in pytest.
|
||||||
try:
|
try:
|
||||||
pmb.helpers.run.user(
|
subprocess.run(
|
||||||
[pmb.config.required_programs["losetup"], "--json"], check=True, output="null"
|
[pmb.config.required_programs["losetup"], "--json"],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
check=True,
|
||||||
)
|
)
|
||||||
except RuntimeError:
|
except subprocess.CalledProcessError:
|
||||||
losetup_missing_json = True
|
losetup_missing_json = True
|
||||||
|
|
||||||
error_message = ""
|
error_message = ""
|
||||||
|
|
|
@ -52,6 +52,13 @@ def device_package(config_file):
|
||||||
return pkgdir
|
return pkgdir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def find_required_programs():
|
||||||
|
"""Fixture to find required programs for pmbootstrap."""
|
||||||
|
|
||||||
|
pmb.config.require_programs()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_devices_find_path(device_package, monkeypatch):
|
def mock_devices_find_path(device_package, monkeypatch):
|
||||||
"""Fixture to mock pmb.helpers.devices.find_path()"""
|
"""Fixture to mock pmb.helpers.devices.find_path()"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue