Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/verify-test-generation-prompts.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Verify test generation prompts

on:
pull_request:
paths:
- ".github/workflows/verify-test-generation-prompts.yaml"
- "shiny/pytest/_generate/**"
# Disabled for now: `shiny add test` is deprecated. Run manually only.
workflow_dispatch:

concurrency:
Expand Down
5 changes: 0 additions & 5 deletions shiny/.agents/skills/shiny-for-python/references/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ pytest test_app.py --headed # watch the browser
pytest test_app.py --tracing retain-on-failure # then: playwright show-trace <trace.zip>
```

## Generate a test with AI

`shiny add test --app app.py` analyzes an app and writes a test file for it
(requires `ANTHROPIC_API_KEY`, or `OPENAI_API_KEY` with `--provider openai`).

## Common mistakes

- Test times out with a blank page → you forgot `page.goto(local_app.url)`.
Expand Down
31 changes: 29 additions & 2 deletions shiny/_main/_generate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import click
import questionary

from ._utils import cli_action, cli_bold, cli_code, path_rel_wd
from ._utils import cli_action, cli_bold, cli_code, cli_warning, path_rel_wd


class ValidationError(Exception):
Expand Down Expand Up @@ -113,14 +113,35 @@ def get_output_file_path(output_file: str | None, app_path: Path) -> Path:
return Path(output_file_val)


def warn_deprecated() -> None:
click.echo(
cli_warning(
click.style(
"`shiny add test` is deprecated and will be removed within the "
"next few releases.",
fg="yellow",
bold=True,
)
),
err=True,
)
click.echo(
click.style(
" Use the `shiny-for-python` skill with an agent harness to "
"generate tests instead.",
fg="yellow",
),
err=True,
)


def generate_test_file(
*,
app_file: str | None,
output_file: str | None,
provider: str,
model: str | None,
) -> None:

try:
validate_api_key(provider)

Expand Down Expand Up @@ -171,11 +192,16 @@ def add() -> None:

@add.command(
"test",
deprecated=True,
help="""Add a test file for a specified Shiny app.

Generate a comprehensive test file for a specified app using AI. The generator
will analyze your app code and create appropriate test cases with assertions.

NOTE: `shiny add test` is deprecated and will be removed within the next few
releases. Use the `shiny-for-python` skill with an agent harness to generate
tests for your Shiny for Python apps instead.

After creating the test file, you can use `pytest` to run the tests:

pytest TEST_FILE
Expand Down Expand Up @@ -210,6 +236,7 @@ def test(
provider: str,
model: str | None,
) -> None:
warn_deprecated()
generate_test_file(
app_file=app, output_file=test_file, provider=provider, model=model
)
11 changes: 11 additions & 0 deletions tests/pytest/test_main_generate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def test_add_group_lists_test_command() -> None:

assert result.exit_code == 0
assert "test" in result.output
assert "deprecated" in result.output.lower()


def test_add_test_warns_about_deprecation(
captured_generate: dict[str, Any],
) -> None:
result = CliRunner().invoke(main, ["add", "test"])

assert result.exit_code == 0
assert "deprecated" in result.output.lower()
assert "shiny-for-python" in result.output


def test_add_test_forwards_options(captured_generate: dict[str, Any]) -> None:
Expand Down
Loading