Skip to content

Commit

Permalink
use silx.test.run_tests from run_tests.py
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Aug 29, 2024
1 parent 9008b3b commit 4c6fbb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
22 changes: 5 additions & 17 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,10 @@ def normalize_option(option):
return os.path.join(PROJECT_PATH, *option_parts[2:])
return option

args = [normalize_option(p) for p in sys.argv[1:] if p != "--installed"]

# Run test on PROJECT_PATH if nothing is specified
without_options = [a for a in args if not a.startswith("-")]
if len(without_options) == 0:
args += [PROJECT_PATH]

argv = ["--rootdir", PROJECT_PATH] + args
test_module = importlib.import_module(f"{PROJECT_NAME}.test")
sys.exit(
subprocess.run(
[
sys.executable,
"-m",
"pytest",
]
+ argv,
check=False,
).returncode
test_module.run_tests(
module=None,
args=[normalize_option(p) for p in sys.argv[1:] if p != "--installed"],
)
)
26 changes: 17 additions & 9 deletions src/silx/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"""This package provides test of the root modules
"""

from __future__ import annotations

from collections.abc import Sequence
import importlib
import logging
import subprocess
Expand All @@ -42,25 +45,21 @@
import silx


def run_tests(module: str = "silx", verbosity: int = 0, args=()):
def run_tests(
module: str | None = "silx",
verbosity: int = 0,
args: Sequence[str] = (),
):
"""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`
"""
# Retrieve folder for packages and file for modules
imported_module = importlib.import_module(module)
if hasattr(imported_module, "__path__"):
tested_path = imported_module.__path__[0]
else:
tested_path = imported_module.__file__

cmd = [
sys.executable,
"-m",
"pytest",
tested_path,
f"--rootdir={silx.__path__[0]}",
"--verbosity",
str(verbosity),
Expand All @@ -70,4 +69,13 @@ def run_tests(module: str = "silx", verbosity: int = 0, args=()):
"-Wignore:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning",
] + list(args)

if module is not None:
# Retrieve folder for packages and file for modules
imported_module = importlib.import_module(module)
cmd.append(
imported_module.__path__[0]
if hasattr(imported_module, "__path__")
else imported_module.__file__
)

return subprocess.run(cmd, check=False).returncode

0 comments on commit 4c6fbb8

Please sign in to comment.