Skip to content

Run the assertion in test_add_extras_only_accepts_one_package - #11055

Merged
radoering merged 1 commit into
python-poetry:mainfrom
dylanpulver:fix/dead-assertion-in-raises
Sep 11, 2026
Merged

Run the assertion in test_add_extras_only_accepts_one_package#11055
radoering merged 1 commit into
python-poetry:mainfrom
dylanpulver:fix/dead-assertion-in-raises

Conversation

@dylanpulver

Copy link
Copy Markdown
Contributor

The assertion in test_add_extras_only_accepts_one_package sits inside the with pytest.raises(...) block, after the call that raises:

with pytest.raises(ValueError) as e:
    tester.execute(command)
    assert (
        str(e.value)
        == "You can only specify one package when using the --extras option"
    )

tester.execute(command) raises, so control leaves the block and the assertion below it never runs. The test still passes, but only because pytest.raises caught the ValueError; the message it names is unchecked.

Moving it out of the block is the whole change. It passes there, and it now fails if the expected message is wrong (changing the expected string gives assert 'You can only...extras option' == 'NOT THE REAL MESSAGE').

tests/console/commands/test_add.py: 84 passed. ruff check and ruff format clean.

Found with an AST scan for assertions positioned after the raising statement inside a pytest.raises block. It was the only one in the repository.

This PR was written with AI assistance (Claude Code), including the scan and the verification above.

The assertion sat inside the `with pytest.raises(...)` block, after the
call that raises, so it never ran and the message it claims to check was
unchecked. Moving it out is enough; it passes, and fails if the expected
message is changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@radoering
radoering merged commit f10c09e into python-poetry:main Sep 11, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants