Skip to content

Commit

Permalink
✅ Only run completion installation tests when the env var `_TYPER_RUN…
Browse files Browse the repository at this point in the history
…_INSTALL_COMPLETION_TESTS` is set (#995)
  • Loading branch information
svlandeg authored Nov 7, 2024
1 parent dcd5078 commit 9f9047d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ set -x
export TERMINAL_WIDTH=3000
# Force disable terminal for tests inside of pytest, takes precedence over GITHUB_ACTIONS env var
export _TYPER_FORCE_DISABLE_TERMINAL=1
# Run autocompletion install tests in the CI
export _TYPER_RUN_INSTALL_COMPLETION_TESTS=1
# It seems xdist-pytest ensures modified sys.path to import relative modules in examples keeps working
pytest --cov --cov-report=term-missing -o console_output_style=progress --numprocesses=auto ${@}
3 changes: 2 additions & 1 deletion tests/test_completion/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from docs_src.commands.index import tutorial001 as mod

from ..utils import needs_bash, needs_linux
from ..utils import needs_bash, needs_linux, requires_completion_permission


@needs_bash
Expand All @@ -26,6 +26,7 @@ def test_show_completion():

@needs_bash
@needs_linux
@requires_completion_permission
def test_install_completion():
bash_completion_path: Path = Path.home() / ".bashrc"
text = ""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_completion/test_completion_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

from docs_src.commands.index import tutorial001 as mod

from ..utils import requires_completion_permission

runner = CliRunner()
app = typer.Typer()
app.command()(mod.main)


@requires_completion_permission
def test_completion_install_no_shell():
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", mod.__file__, "--install-completion"],
Expand All @@ -28,6 +31,7 @@ def test_completion_install_no_shell():
assert "Option '--install-completion' requires an argument" in result.stderr


@requires_completion_permission
def test_completion_install_bash():
bash_completion_path: Path = Path.home() / ".bashrc"
text = ""
Expand Down Expand Up @@ -67,6 +71,7 @@ def test_completion_install_bash():
)


@requires_completion_permission
def test_completion_install_zsh():
completion_path: Path = Path.home() / ".zshrc"
text = ""
Expand Down Expand Up @@ -104,6 +109,7 @@ def test_completion_install_zsh():
assert "compdef _tutorial001py_completion tutorial001.py" in install_content


@requires_completion_permission
def test_completion_install_fish():
script_path = Path(mod.__file__)
completion_path: Path = (
Expand Down Expand Up @@ -133,6 +139,7 @@ def test_completion_install_fish():
assert "Completion will take effect once you restart the terminal" in result.stdout


@requires_completion_permission
def test_completion_install_powershell():
completion_path: Path = (
Path.home() / ".config/powershell/Microsoft.PowerShell_profile.ps1"
Expand Down
3 changes: 3 additions & 0 deletions tests/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from typer.models import ParameterInfo, TyperInfo
from typer.testing import CliRunner

from .utils import requires_completion_permission

runner = CliRunner()


Expand Down Expand Up @@ -74,6 +76,7 @@ def convert(
ParameterInfo(click_type=CustomClickParser())


@requires_completion_permission
def test_install_invalid_shell():
app = typer.Typer()

Expand Down
6 changes: 6 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from os import getenv

import pytest

Expand All @@ -25,3 +26,8 @@
needs_bash = pytest.mark.skipif(
not shellingham or not shell or "bash" not in shell, reason="Test requires Bash"
)

requires_completion_permission = pytest.mark.skipif(
not getenv("_TYPER_RUN_INSTALL_COMPLETION_TESTS", False),
reason="Test requires permission to run completion installation tests",
)

0 comments on commit 9f9047d

Please sign in to comment.