diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5d9805f7..8114a816 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -33,7 +33,7 @@ codespell: pytest: stage: test 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.name CI'" - "echo 'build ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers" diff --git a/pmb/config/init.py b/pmb/config/init.py index 4596a9ac..6cb09c25 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -32,6 +32,7 @@ import pmb.chroot.zap import pmb.parse.deviceinfo from pmb.parse.deviceinfo import Deviceinfo import pmb.parse._apkbuild +import subprocess def require_programs() -> None: @@ -50,11 +51,16 @@ def require_programs() -> None: if "losetup" not in missing: # Check if losetup supports the --json argument. Use the absolute path # 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: - pmb.helpers.run.user( - [pmb.config.required_programs["losetup"], "--json"], check=True, output="null" + subprocess.run( + [pmb.config.required_programs["losetup"], "--json"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=True, ) - except RuntimeError: + except subprocess.CalledProcessError: losetup_missing_json = True error_message = "" diff --git a/pmb/conftest.py b/pmb/conftest.py index ba2506cc..bc0694cb 100644 --- a/pmb/conftest.py +++ b/pmb/conftest.py @@ -52,6 +52,13 @@ def device_package(config_file): return pkgdir +@pytest.fixture(autouse=True) +def find_required_programs(): + """Fixture to find required programs for pmbootstrap.""" + + pmb.config.require_programs() + + @pytest.fixture def mock_devices_find_path(device_package, monkeypatch): """Fixture to mock pmb.helpers.devices.find_path()"""