call pytest via subprocess once more
import os
import pathlib
import subprocess
-import sys
-
-from pymedphys._imports import pytest
import pymedphys._utilities.test as pmp_test_utils
@@ -26,37 +23,27 @@ PYLINT_RC_FILE = LIBRARY_ROOT.joinpath(".pylintrc")
def run_tests(_, remaining):
- original_cwd = os.getcwd()
+ _call_pytest(remaining, "pytest")
- os.chdir(LIBRARY_ROOT)
- print(f"Running tests with cwd set to:\n {os.getcwd()}\n")
- try:
- exit_code = pytest.main(remaining + ["--pyargs", "pymedphys"])
- finally:
- os.chdir(original_cwd)
-
- sys.exit(exit_code)
+def run_doctests(_, remaining):
+ remaining = ["--doctest-modules"] + remaining
+ _call_pytest(remaining, "doctests")
-def run_pylint(_, remaining):
+def _call_pytest(remaining, label):
original_cwd = os.getcwd()
- if LIBRARY_ROOT.parent.name == "lib":
- working_directory_to_use = LIBRARY_ROOT.parent.parent
- else:
- working_directory_to_use = LIBRARY_ROOT.parent
-
- os.chdir(working_directory_to_use)
- print(f"Linting with cwd set to:\n {os.getcwd()}\n")
+ os.chdir(LIBRARY_ROOT)
+ print(f"Running {label} with cwd set to:\n {os.getcwd()}\n")
python_executable = pmp_test_utils.get_executable_even_when_embedded()
command = [
python_executable,
"-m",
- "pylint",
+ "pytest",
+ "--pyargs",
"pymedphys",
- f"--rcfile={str(PYLINT_RC_FILE)}",
] + remaining
try:
@@ -65,20 +52,24 @@ def run_pylint(_, remaining):
os.chdir(original_cwd)
-def run_doctests(_, remaining):
+def run_pylint(_, remaining):
original_cwd = os.getcwd()
- os.chdir(LIBRARY_ROOT)
- print(f"Running doctests with cwd set to:\n {os.getcwd()}\n")
+ if LIBRARY_ROOT.parent.name == "lib":
+ working_directory_to_use = LIBRARY_ROOT.parent.parent
+ else:
+ working_directory_to_use = LIBRARY_ROOT.parent
+
+ os.chdir(working_directory_to_use)
+ print(f"Linting with cwd set to:\n {os.getcwd()}\n")
python_executable = pmp_test_utils.get_executable_even_when_embedded()
command = [
python_executable,
"-m",
- "pytest",
- "--pyargs",
+ "pylint",
"pymedphys",
- "--doctest-modules",
+ f"--rcfile={str(PYLINT_RC_FILE)}",
] + remaining
try:
