Skip to content
Myr

🐛 Ensure that an envvar set for `typer.Option` works as expected (#1788)

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 959a356 · Browse files · 2 files+13 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−0 removed

  • tests:+12 added−0 removed
  • other:+1 added−0 removed

2 files+13 added−0 removed

modified:tests/test_others.py+12 added
323 unmodified lines
324 result = runner.invoke(app)325 assert "[]" in result.output326327328def test_option_uses_envvar_when_required():329 app = typer.Typer()330331 @app.command()332 def main(user: Annotated[str, typer.Option(envvar="ME")]):333 print(f"Hello {user}")334335 result = runner.invoke(app, env={"ME": "rick"})336 assert result.exit_code == 0337 assert "Hello rick" in result.output338339340def test_completion_argument():341 file_path = Path(__file__).parent / "assets/completion_argument.py"342 result = subprocess.run(343 [sys.executable, "-m", "coverage", "run", str(file_path), "E"],
130 unmodified lines
modified:typer/core.py+1 added
670 unmodified lines
671672 # Absent environment variable or an empty string is interpreted as unset.673 if rv is None:674 return None675 return rv676677 def resolve_envvar_value(self, ctx: _click.Context) -> str | None:678 rv = super().resolve_envvar_value(ctx)679
531 unmodified lines