From ae5674775686dcec430eb38aa598e8750077c8ab Mon Sep 17 00:00:00 2001 From: Matthew Broadway Date: Tue, 2 Jan 2024 20:51:08 +0000 Subject: [PATCH] improved logging in case of run_python failure --- tests/import_hook/common.py | 21 +++++++++++++++------ tests/import_hook/test_project_importer.py | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/import_hook/common.py b/tests/import_hook/common.py index 80328311a..64572dd78 100644 --- a/tests/import_hook/common.py +++ b/tests/import_hook/common.py @@ -16,7 +16,6 @@ verbose = True - script_dir = Path(__file__).resolve().parent maturin_dir = script_dir.parent.parent test_crates = maturin_dir / "test-crates" @@ -30,7 +29,6 @@ import_hook.install() """ - EXCLUDED_PROJECTS = { "hello-world", # not imported as a python module (subprocess only) "license-test", # not imported as a python module (subprocess only) @@ -88,16 +86,18 @@ def run_python( message = "\n".join( [ "-" * 40, - "ERROR:", + "Called Process Error:", subprocess.list2cmdline(cmd), - "", + "Output:", output, "-" * 40, ] ) - print(message, file=sys.stderr) + print(message) if not expect_error: - raise + # re-raising the CalledProcessError would cause + # unnecessary output since we are already printing it above + raise RuntimeError("run_python failed") from None duration = time.perf_counter() - start output = output.replace("\r\n", "\n") @@ -188,6 +188,15 @@ def is_installed_correctly(project_name: str, project_dir: Path, is_mixed: bool) f"checking if {project_name} is installed correctly. " f"{is_mixed=}, {installed_as_pth=} {installed_editable_with_direct_url=}" ) + + proc = subprocess.run( + [sys.executable, "-m", "pip", "show", "--disable-pip-version-check", "-f", project_name], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + check=False, + ) + output = "None" if proc.stdout is None else proc.stdout.decode() + log(f"pip output (returned {proc.returncode}):\n{output}") return installed_editable_with_direct_url and (installed_as_pth == is_mixed) diff --git a/tests/import_hook/test_project_importer.py b/tests/import_hook/test_project_importer.py index 926549721..fabfa6634 100644 --- a/tests/import_hook/test_project_importer.py +++ b/tests/import_hook/test_project_importer.py @@ -160,6 +160,7 @@ def test_do_not_rebuild_if_installed_non_editable(workspace: Path, project_name: uninstall(project_name) project_dir = get_project_copy(test_crates / project_name, workspace / project_name) install_non_editable(project_dir) + assert is_installed_correctly(project_name, project_dir, is_mixed="mixed" in project_name) check_installed_outside_project = workspace / "check_installed" check_installed_outside_project.mkdir()