From 9d40f7f3833a28ea526a80f5b0466ac680c63c88 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Fri, 12 Jan 2024 11:31:08 +0100 Subject: [PATCH 1/2] run tests in subprocess to avoid import issues --- src/silx/test/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/silx/test/__init__.py b/src/silx/test/__init__.py index 4a9b365fd3..0f3d5ded04 100644 --- a/src/silx/test/__init__.py +++ b/src/silx/test/__init__.py @@ -1,6 +1,6 @@ # /*########################################################################## # -# Copyright (c) 2015-2022 European Synchrotron Radiation Facility +# Copyright (c) 2015-2024 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -25,6 +25,8 @@ """ import logging +import subprocess +import sys try: @@ -37,14 +39,17 @@ def run_tests(module: str = "silx", verbosity: int = 0, args=()): - """Run tests + """Run tests in a subprocess :param module: Name of the silx module to test (default: 'silx') :param verbosity: Requested level of verbosity :param args: List of extra arguments to pass to `pytest` """ - return pytest.main( + return subprocess.run( [ + sys.executable, + "-m", + "pytest", "--pyargs", module, "--verbosity", @@ -53,5 +58,6 @@ def run_tests(module: str = "silx", verbosity: int = 0, args=()): '-o python_classes=["Test"]', '-o python_functions=["test"]', ] - + list(args) - ) + + list(args), + check=False, + ).returncode From 6edad764e895055440cbd19ecc3c409c1ad9ddd1 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Fri, 12 Jan 2024 11:31:26 +0100 Subject: [PATCH 2/2] normalize path and run tests in subprocess --- run_tests.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/run_tests.py b/run_tests.py index 0651511475..63f5612862 100755 --- a/run_tests.py +++ b/run_tests.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # /*########################################################################## # -# Copyright (c) 2015-2022 European Synchrotron Radiation Facility +# Copyright (c) 2015-2024 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -40,6 +40,7 @@ import subprocess import sys import sysconfig +from pathlib import Path # Capture all default warnings @@ -153,15 +154,13 @@ def import_project_module(project_name, project_dir): if __name__ == "__main__": # Needed for multiprocessing support on Windows - import pytest - PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) PROJECT_NAME = get_project_name(PROJECT_DIR) logger.info("Project name: %s", PROJECT_NAME) project_module = import_project_module(PROJECT_NAME, PROJECT_DIR) PROJECT_VERSION = getattr(project_module, "version", "") - PROJECT_PATH = project_module.__path__[0] + PROJECT_PATH = str(Path(project_module.__path__[0]).resolve()) def normalize_option(option): option_parts = option.split(os.path.sep) @@ -179,4 +178,14 @@ def normalize_option(option): args += [PROJECT_PATH] argv = ["--rootdir", PROJECT_PATH] + args - sys.exit(pytest.main(argv)) + sys.exit( + subprocess.run( + [ + sys.executable, + "-m", + "pytest", + ] + + argv, + check=False, + ).returncode + )