From f58e31efe60ffbfd7a5ac0ebfd8bbb093ab37d09 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Mon, 24 Jul 2023 13:48:56 +0300 Subject: [PATCH] Run tests sequentially Run tests sequentially, because in subsequent commits we will add Qt tests that do not play nice when `pytest` creates new processes [1]. Also, remove the pytest wrapper, whose main task was to decide if tests can run in parallel [2]. [1]: https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-2393 [2]: https://github.com/freedomofpress/dangerzone/issues/217 --- Makefile | 3 +- dev_scripts/pytest-wrapper.py | 61 ----------------------------------- 2 files changed, 2 insertions(+), 62 deletions(-) delete mode 100755 dev_scripts/pytest-wrapper.py diff --git a/Makefile b/Makefile index 900d5a8..87636b4 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,8 @@ lint-apply: lint-black-apply lint-isort-apply ## apply all the linter's suggesti .PHONY: test test: - python ./dev_scripts/pytest-wrapper.py -v --cov --ignore dev_scripts + pytest -v --cov --ignore dev_scripts + # Makefile self-help borrowed from the securedrop-client project # Explaination of the below shell command should it ever break. diff --git a/dev_scripts/pytest-wrapper.py b/dev_scripts/pytest-wrapper.py deleted file mode 100755 index 737cf45..0000000 --- a/dev_scripts/pytest-wrapper.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -# PyTest Wrapper script - temporary solution to tests failing non-deterministically [1] -# This is only fixed in podman v4.3.0. The wrapper essentially runs the tests in sequence -# when the podman version is lower. -# -# [1]: https://github.com/freedomofpress/dangerzone/issues/217 - -# FIXME this whole script should be removed and the respective Makefile calling line -# replaced once all supported platforms have a podman version >= v4.3.0. - -import re -import subprocess -import sys - -from pkg_resources import parse_version - -from dangerzone.isolation_provider.container import Container - -PODMAN_MIN_VERSION = "4.3.0" - - -def get_podman_version(): - result = subprocess.run( - ["podman", "version", "--format", "'{{.Client.Version}}'"], capture_output=True - ) - version = result.stdout.decode()[:-1] # trim trailing \n - return version.split("-dev")[0] # exclude "-dev" suffix from version - - -def run_tests(pytest_args): - cmd = ["pytest"] + pytest_args - try: - subprocess.run(cmd, check=True) - except subprocess.CalledProcessError: - sys.exit(1) - - -def run_tests_in_parallel(pytest_args): - print("running tests in parallel") - run_tests(pytest_args + ["-n", "4"]) - - -def run_tests_in_sequence(pytest_args): - print("running tests sequentially") - run_tests(pytest_args) - - -if __name__ == "__main__": - pytest_args = sys.argv[1:] # exclude program names - - if Container.get_runtime_name() == "docker": - run_tests_in_parallel(pytest_args) - else: - podman_ver_minimum_parallel = parse_version(PODMAN_MIN_VERSION) - podman_ver_current = parse_version(get_podman_version()) - if podman_ver_current >= podman_ver_minimum_parallel: - run_tests_in_parallel(pytest_args) - else: - run_tests_in_sequence(pytest_args)