Fix publish --build prompt behavior in non-interactive mode#10769
Fix publish --build prompt behavior in non-interactive mode#10769SergioChan wants to merge 3 commits intopython-poetry:mainfrom
Conversation
Reviewer's GuideAdjusts the publish command to respect non-interactive mode when build artifacts already exist, and adds a regression test ensuring the confirmation prompt is skipped while the build/publish flow still runs. Sequence diagram for non-interactive publish --build with existing artifactssequenceDiagram
actor User
participant CLI
participant PublishCommand
participant IO
participant Publisher
User->>CLI: poetry publish --build --no-interaction
CLI->>PublishCommand: handle()
PublishCommand->>PublishCommand: option("build") == True
PublishCommand->>Publisher: check files
Publisher-->>PublishCommand: files list (non empty)
PublishCommand->>IO: is_interactive()
IO-->>PublishCommand: False
Note over PublishCommand: Condition publisher.files and IO.is_interactive() fails
PublishCommand->>Publisher: build()
Publisher-->>PublishCommand: build result
PublishCommand->>Publisher: publish()
Publisher-->>PublishCommand: publish result
PublishCommand-->>CLI: exit code 0
CLI-->>User: Command completed without prompt
Flow diagram for publish --build prompt and abort logicflowchart TD
A[Start handle] --> B{option build is True}
B -- No --> Z[Proceed with publish without build]
B -- Yes --> C{publisher.files is non empty}
C -- No --> D[Run build]
D --> E[Run publish]
E --> F[Return success]
C -- Yes --> G{IO is_interactive is True}
G -- No --> D
G -- Yes --> H{confirm Build anyway}
H -- Yes --> D
H -- No --> I[Print Aborted]
I --> J[Return failure]
Z --> E
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/console/commands/test_publish.py" line_range="221-230" />
<code_context>
assert "- Uploading simple_project-1.2.3-py2.py3-none-any.whl" in error
+
+
+def test_publish_build_no_interaction_skips_confirmation(
+ app_tester: ApplicationTester, mocker: MockerFixture
+) -> None:
+ mocker.patch(
+ "poetry.publishing.publisher.Publisher.files",
+ new_callable=PropertyMock,
+ return_value=[Path("dist/simple_project-1.2.3-py2.py3-none-any.whl")],
+ )
+ confirm = mocker.patch("poetry.console.commands.publish.PublishCommand.confirm")
+ command_call = mocker.patch("poetry.console.commands.publish.PublishCommand.call")
+ publisher_publish = mocker.patch("poetry.publishing.Publisher.publish")
+
+ exit_code = app_tester.execute("publish --build --no-interaction --dry-run")
+
+ assert exit_code == 0
+ confirm.assert_not_called()
+ command_call.assert_called_once_with("build", args="--output dist")
+ assert publisher_publish.call_count == 1
</code_context>
<issue_to_address>
**suggestion (testing):** Also assert that the confirmation prompt text is not present in the command output
To better cover the user-facing behavior, please also assert that the confirmation prompt text (e.g. "Build anyway?") does not appear in stdout/stderr when running with `--no-interaction`, by capturing the `app_tester` output as done in other tests.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| def test_publish_build_no_interaction_skips_confirmation( | ||
| app_tester: ApplicationTester, mocker: MockerFixture | ||
| ) -> None: | ||
| mocker.patch( | ||
| "poetry.publishing.publisher.Publisher.files", | ||
| new_callable=PropertyMock, | ||
| return_value=[Path("dist/simple_project-1.2.3-py2.py3-none-any.whl")], | ||
| ) | ||
| confirm = mocker.patch("poetry.console.commands.publish.PublishCommand.confirm") | ||
| command_call = mocker.patch("poetry.console.commands.publish.PublishCommand.call") |
There was a problem hiding this comment.
suggestion (testing): Also assert that the confirmation prompt text is not present in the command output
To better cover the user-facing behavior, please also assert that the confirmation prompt text (e.g. "Build anyway?") does not appear in stdout/stderr when running with --no-interaction, by capturing the app_tester output as done in other tests.
|
Addressed in 8614fbc.
Targeted validation:
|
|
What's the difference between this and #10768? |
Pull Request Check List
Resolves: #10760
Summary
--no-interactioninpoetry publish --buildwhendist/already contains artifacts.Testing
poetry run pytest tests/console/commands/test_publish.py -qdist/artifacts under non-interactive execution.Summary by Sourcery
Tests:
poetry publish --build --no-interactionskips the confirmation prompt and still performs the build/publish flow when artifacts already exist indist/.