|
5 | 5 | from pathlib import Path |
6 | 6 | from typing import TYPE_CHECKING |
7 | 7 | from typing import NoReturn |
| 8 | +from unittest.mock import PropertyMock |
8 | 9 |
|
9 | 10 | import pytest |
10 | 11 | import requests |
@@ -215,3 +216,31 @@ def test_publish_dist_dir_and_build_options( |
215 | 216 | assert "Publishing simple-project (1.2.3) to PyPI" in output |
216 | 217 | assert "- Uploading simple_project-1.2.3.tar.gz" in error |
217 | 218 | assert "- Uploading simple_project-1.2.3-py2.py3-none-any.whl" in error |
| 219 | + |
| 220 | + |
| 221 | +def test_publish_build_no_interaction_skips_confirmation( |
| 222 | + app_tester: ApplicationTester, mocker: MockerFixture |
| 223 | +) -> None: |
| 224 | + mocker.patch( |
| 225 | + "poetry.publishing.publisher.Publisher.files", |
| 226 | + new_callable=PropertyMock, |
| 227 | + return_value=[Path("dist/simple_project-1.2.3-py2.py3-none-any.whl")], |
| 228 | + ) |
| 229 | + confirm = mocker.patch("poetry.console.commands.publish.PublishCommand.confirm") |
| 230 | + command_call = mocker.patch("poetry.console.commands.publish.PublishCommand.call") |
| 231 | + publisher_publish = mocker.patch("poetry.publishing.Publisher.publish") |
| 232 | + |
| 233 | + exit_code = app_tester.execute("publish --build --no-interaction --dry-run") |
| 234 | + |
| 235 | + assert exit_code == 0 |
| 236 | + output = app_tester.io.fetch_output() |
| 237 | + error = app_tester.io.fetch_error() |
| 238 | + |
| 239 | + confirm.assert_not_called() |
| 240 | + assert "Build anyway?" not in output |
| 241 | + assert "Build anyway?" not in error |
| 242 | + assert ( |
| 243 | + "Warning: There are 1 files ready for publishing in dist. Build anyway!" |
| 244 | + ) in output |
| 245 | + command_call.assert_called_once_with("build", args="--output dist") |
| 246 | + assert publisher_publish.call_count == 1 |
0 commit comments