✅ Only run completion installation tests when the env var `_TYPER_RUN_INSTALL_COMPLETION_TESTS` is set (#995)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sofie Van Landeghem · committed by GitHub · parent dcd5078 · Browse files · 5 files·+20 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+20 added−1 removed
- tests:+18 added−1 removed
- other:+2 added−0 removed
Provenance
- Commit
9f9047d- Tree
e0fa3c7- Author
Sofie Van Landeghem <svlandeg@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
dcd5078
5 files changed+20 added−1 removed
modified:scripts/test.sh+2 added
5 unmodified lines6789101112135 unmodified lines# For tests, a large terminal widthexport TERMINAL_WIDTH=3000# Force disable terminal for tests inside of pytest, takes precedence over GITHUB_ACTIONS env varexport _TYPER_FORCE_DISABLE_TERMINAL=1# Run autocompletion install tests in the CIexport _TYPER_RUN_INSTALL_COMPLETION_TESTS=1# It seems xdist-pytest ensures modified sys.path to import relative modules in examples keeps workingpytest --cov --cov-report=term-missing -o console_output_style=progress --numprocesses=auto ${@}modified:tests/test_completion/test_completion_install.py+7 added
8 unmodified lines9 from typer.testing import CliRunner10 11 from docs_src.commands.index import tutorial001 as mod12 13+from ..utils import requires_completion_permission14+15 runner = CliRunner()16 app = typer.Typer()17 app.command()(mod.main)18 19 20+@requires_completion_permission21 def test_completion_install_no_shell():22 result = subprocess.run(23 [sys.executable, "-m", "coverage", "run", mod.__file__, "--install-completion"],24 capture_output=True,5 unmodified lines30 )31 assert "Option '--install-completion' requires an argument" in result.stderr32 33 34+@requires_completion_permission35 def test_completion_install_bash():36 bash_completion_path: Path = Path.home() / ".bashrc"37 text = ""38 if bash_completion_path.is_file():31 unmodified lines70 in install_content71 )72 73 74+@requires_completion_permission75 def test_completion_install_zsh():76 completion_path: Path = Path.home() / ".zshrc"77 text = ""78 if not completion_path.is_file(): # pragma: no cover29 unmodified lines108 install_source_path.unlink()109 assert "compdef _tutorial001py_completion tutorial001.py" in install_content110 111 112+@requires_completion_permission113 def test_completion_install_fish():114 script_path = Path(mod.__file__)115 completion_path: Path = (116 Path.home() / f".config/fish/completions/{script_path.name}.fish"21 unmodified lines138 assert "completion installed in" in result.stdout139 assert "Completion will take effect once you restart the terminal" in result.stdout140 141 142+@requires_completion_permission143 def test_completion_install_powershell():144 completion_path: Path = (145 Path.home() / ".config/powershell/Microsoft.PowerShell_profile.ps1"146 )26 unmodified linesmodified:tests/test_completion/test_completion.py+2 added-1 removed
3 unmodified lines4 from pathlib import Path5 6 from docs_src.commands.index import tutorial001 as mod7 8-from ..utils import needs_bash, needs_linux8+from ..utils import needs_bash, needs_linux, requires_completion_permission9 10 11 @needs_bash12 @needs_linux12 unmodified lines25 26 27 @needs_bash28 @needs_linux29+@requires_completion_permission30 def test_install_completion():31 bash_completion_path: Path = Path.home() / ".bashrc"32 text = ""33 if bash_completion_path.is_file(): # pragma: no cover131 unmodified linesmodified:tests/test_others.py+3 added
13 unmodified lines14 from typer.main import solve_typer_info_defaults, solve_typer_info_help15 from typer.models import ParameterInfo, TyperInfo16 from typer.testing import CliRunner17 18+from .utils import requires_completion_permission19+20 runner = CliRunner()21 22 23 def test_help_from_info():51 unmodified lines75 ParameterInfo(parser=custom_parser)76 ParameterInfo(click_type=CustomClickParser())77 78 79+@requires_completion_permission80 def test_install_invalid_shell():81 app = typer.Typer()82 83 @app.command()197 unmodified linesmodified:tests/utils.py+6 added
1 import sys2+from os import getenv3 4 import pytest5 6 try:18 unmodified lines25 26 needs_bash = pytest.mark.skipif(27 not shellingham or not shell or "bash" not in shell, reason="Test requires Bash"28 )29+30+requires_completion_permission = pytest.mark.skipif(31+ not getenv("_TYPER_RUN_INSTALL_COMPLETION_TESTS", False),32+ reason="Test requires permission to run completion installation tests",33+)