From a5b7557140eda1f494050a791d51469ca6483805 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Sat, 24 Aug 2024 23:08:27 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20`needs=5Fbash`=20test=20fixtu?= =?UTF-8?q?re=20(#888)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- tests/test_completion/test_completion.py | 4 +++- tests/utils.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_completion/test_completion.py b/tests/test_completion/test_completion.py index 703373b226..36581aba09 100644 --- a/tests/test_completion/test_completion.py +++ b/tests/test_completion/test_completion.py @@ -5,9 +5,10 @@ from docs_src.commands.index import tutorial001 as mod -from ..utils import needs_linux +from ..utils import needs_bash, needs_linux +@needs_bash @needs_linux def test_show_completion(): result = subprocess.run( @@ -23,6 +24,7 @@ def test_show_completion(): assert "_TUTORIAL001.PY_COMPLETE=complete_bash" in result.stdout +@needs_bash @needs_linux def test_install_completion(): bash_completion_path: Path = Path.home() / ".bashrc" diff --git a/tests/utils.py b/tests/utils.py index 9b503ff799..8f51332ee2 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -2,6 +2,18 @@ import pytest +try: + import shellingham + from shellingham import ShellDetectionFailure + + shell = shellingham.detect_shell()[0] +except ImportError: # pragma: no cover + shellingham = None + shell = None +except ShellDetectionFailure: # pragma: no cover + shell = None + + needs_py310 = pytest.mark.skipif( sys.version_info < (3, 10), reason="requires python3.10+" ) @@ -9,3 +21,7 @@ needs_linux = pytest.mark.skipif( not sys.platform.startswith("linux"), reason="Test requires Linux" ) + +needs_bash = pytest.mark.skipif( + not shellingham or not shell or "bash" not in shell, reason="Test requires Bash" +)