Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(console): do not fail on warnings on check command #9983

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ poetry check
### Options

* `--lock`: Verifies that `poetry.lock` exists for the current `pyproject.toml`.
abn marked this conversation as resolved.
Show resolved Hide resolved
* `--strict`: Fail if check reports warnings.

## search

Expand Down
16 changes: 13 additions & 3 deletions src/poetry/console/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class CheckCommand(Command):
"Checks that <comment>poetry.lock</> exists for the current"
" version of <comment>pyproject.toml</>.",
),
option(
"strict",
None,
"Fail if check reports warnings.",
),
]

def _validate_classifiers(
Expand Down Expand Up @@ -161,15 +166,20 @@ def handle(self) -> int:
"Run `poetry lock` to fix the lock file."
]

return_code = 0

if check_result["errors"] or (
check_result["warnings"] and self.option("strict")
):
return_code = 1

if not check_result["errors"] and not check_result["warnings"]:
self.info("All set!")
radoering marked this conversation as resolved.
Show resolved Hide resolved

return 0

for error in check_result["errors"]:
self.line_error(f"<error>Error: {error}</error>")

for error in check_result["warnings"]:
self.line_error(f"<warning>Warning: {error}</warning>")

return 1
return return_code
16 changes: 14 additions & 2 deletions tests/console/commands/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,26 @@ def test_check_valid(tester: CommandTester) -> None:
assert tester.io.fetch_output() == expected
sourcery-ai[bot] marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.parametrize(
["args", "expected_status"],
[
([], 0),
abn marked this conversation as resolved.
Show resolved Hide resolved
(["--strict"], 1),
],
)
def test_check_valid_legacy(
mocker: MockerFixture, tester: CommandTester, fixture_dir: FixtureDirGetter
args: list[str],
expected_status: int,
mocker: MockerFixture,
tester: CommandTester,
fixture_dir: FixtureDirGetter,
) -> None:
mocker.patch(
"poetry.poetry.Poetry.file",
return_value=TOMLFile(fixture_dir("simple_project_legacy") / "pyproject.toml"),
new_callable=mocker.PropertyMock,
)
tester.execute()
tester.execute(" ".join(args))

expected = (
"Warning: [tool.poetry.name] is deprecated. Use [project.name] instead.\n"
Expand Down Expand Up @@ -125,6 +136,7 @@ def test_check_valid_legacy(
)

assert tester.io.fetch_error() == expected
assert tester.status_code == expected_status


def test_check_invalid_dep_name_same_as_project_name(
Expand Down
Loading