From 6d4d4a706d4ffaaba19b1f2c2718d0842c1407a7 Mon Sep 17 00:00:00 2001 From: Cunshun Xia Date: Sat, 13 Apr 2024 23:55:38 +0800 Subject: [PATCH] Fix test_console failure finding pipdeptree in other environments (#351) When we are using pytest in packaging process, we may not get the `/usr/bin/pipdeptree` as we need. So, let's use the `PATH` env to get the binary instead. fix: https://github.com/tox-dev/pipdeptree/issues/348 Signed-off-by: cunshunxia --- pyproject.toml | 1 + tests/test_pipdeptree.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d925e8c..5f186e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ optional-dependencies.test = [ "covdefaults>=2.3", "diff-cover>=8.0.1", "pytest>=7.4.3", + "pytest-console-scripts>=1.4.1", "pytest-cov>=4.1", "pytest-mock>=3.12", "virtualenv<21,>=20.25", diff --git a/tests/test_pipdeptree.py b/tests/test_pipdeptree.py index 5816010..7b565b0 100644 --- a/tests/test_pipdeptree.py +++ b/tests/test_pipdeptree.py @@ -1,13 +1,17 @@ from __future__ import annotations import sys -from pathlib import Path from subprocess import check_call # noqa: S404 +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from pytest_console_scripts import ScriptRunner def test_main() -> None: check_call([sys.executable, "-m", "pipdeptree", "--help"]) -def test_console() -> None: - check_call([Path(sys.executable).parent / "pipdeptree", "--help"]) +def test_console(script_runner: ScriptRunner) -> None: + result = script_runner.run("pipdeptree", "--help") + assert result.success