Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Fixed test execution #4043

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -40,6 +40,7 @@
import subprocess
import sys
import sysconfig
from pathlib import Path


# Capture all default warnings
Expand Down Expand Up @@ -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())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use resolve to use canonical path


def normalize_option(option):
option_parts = option.split(os.path.sep)
Expand All @@ -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
)
16 changes: 11 additions & 5 deletions src/silx/test/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,6 +25,8 @@
"""

import logging
import subprocess
import sys


try:
Expand All @@ -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",
Expand All @@ -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
Loading