diff --git a/src/poetry/console/commands/build.py b/src/poetry/console/commands/build.py index a9d056896b3..86626fcf64a 100644 --- a/src/poetry/console/commands/build.py +++ b/src/poetry/console/commands/build.py @@ -2,18 +2,12 @@ from pathlib import Path -from typing import TYPE_CHECKING - from cleo.helpers import option from poetry.console.commands.env_command import EnvCommand from poetry.utils.env import build_environment -if TYPE_CHECKING: - from pathlib import Path - - class BuildCommand(EnvCommand): name = "build" description = "Builds a package, as a tarball and a wheel by default." diff --git a/tests/console/commands/test_build.py b/tests/console/commands/test_build.py index c04717ea7b7..023e855ee59 100644 --- a/tests/console/commands/test_build.py +++ b/tests/console/commands/test_build.py @@ -67,7 +67,6 @@ def test_build_with_multiple_readme_files( tmp_path: Path, tmp_venv: VirtualEnv, command_tester_factory: CommandTesterFactory, - output_dir: str, ) -> None: source_dir = fixture_dir("with_multiple_readme_files") target_dir = tmp_path / "project" @@ -75,17 +74,9 @@ def test_build_with_multiple_readme_files( poetry = Factory().create_poetry(target_dir) tester = command_tester_factory("build", poetry, environment=tmp_venv) + tester.execute() - if output_dir is None: - tester.execute() - build_dir = target_dir / "dist" - elif output_dir == "absolute": - tester.execute(f"--output {target_dir / 'tmp/dist'}") - build_dir = target_dir / "tmp/dist" - else: - tester.execute(f"--output {output_dir}") - build_dir = target_dir / output_dir - + build_dir = target_dir / "dist" assert build_dir.exists() sdist_file = build_dir / "my_package-0.1.tar.gz" @@ -101,3 +92,27 @@ def test_build_with_multiple_readme_files( assert "my_package-0.1/README-1.rst" in sdist_content assert "my_package-0.1/README-2.rst" in sdist_content + + +@pytest.mark.parametrize( + "output_dir", [None, "dist", "test/dir", "../dist", "absolute"] +) +def test_build_output_option( + tmp_tester: CommandTester, + tmp_project_path: Path, + tmp_poetry: Poetry, + output_dir: str, +) -> None: + if output_dir is None: + tmp_tester.execute() + build_dir = tmp_project_path / "dist" + elif output_dir == "absolute": + tmp_tester.execute(f"--output {tmp_project_path / 'tmp/dist'}") + build_dir = tmp_project_path / "tmp/dist" + else: + tmp_tester.execute(f"--output {output_dir}") + build_dir = tmp_project_path / output_dir + + build_artifacts = tuple(build_dir.glob(get_package_glob(tmp_poetry))) + assert len(build_artifacts) > 0 + assert all(archive.exists() for archive in build_artifacts)