Skip to content

tests: add real coverage for _generate_installed_modules - #7525

Closed
hikmetba-bit wants to merge 1 commit into
getsentry:masterfrom
hikmetba-bit:test/generate-installed-modules
Closed

hikmetba-bit wants to merge 1 commit into
getsentry:masterfrom
hikmetba-bit:test/generate-installed-modules

Conversation

@hikmetba-bit

Copy link
Copy Markdown

Summary

Fixes #4594.

The previous test for _generate_installed_modules was removed in #4593 because it was pointless — it just re-implemented the function's own loop and compared the two, so it never exercised any behavior independent of the implementation.

Change

Added test_generate_installed_modules to tests/test_utils.py, which mocks importlib.metadata.distributions() with a small fixed set of fake distributions and asserts on the actual contract:

  • names are normalized case-insensitively
  • an entry with no Name in its metadata is skipped
  • an entry with no version is skipped
  • a case-insensitive duplicate name is skipped in favor of the first occurrence

This is independent of whatever packages happen to be installed in the test environment, so it doesn't need the tox-pinned-environment approach suggested in the issue.

Test plan

  • python -m pytest tests/test_utils.py -k installed_modules -v — both test_installed_modules_caching (existing) and the new test_generate_installed_modules pass.
  • Verified the new test actually catches a regression: locally removed the normalized_name not in yielded dedup check from _generate_installed_modules, confirmed the test fails with a clear diff, then reverted.

🤖 Generated with Claude Code

Fixes getsentry#4594.

The previous test for this function (removed in getsentry#4593) just mirrored
the implementation's own loop, so it never exercised any behavior
independent of the code it was testing.

This mocks importlib.metadata.distributions() with a small fixed set
of fake distributions and asserts on the actual contract: names are
normalized case-insensitively, entries with no Name are skipped,
entries with no version are skipped, and a case-insensitive duplicate
name is skipped in favor of the first occurrence. Verified the test
actually catches a regression by temporarily breaking the dedup check
locally and confirming the test fails, then reverting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@hikmetba-bit
hikmetba-bit requested a review from a team as a code owner September 16, 2026 18:01

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3e86efa. Configure here.

Comment thread tests/test_utils.py

with mock.patch(
"importlib.metadata.distributions", return_value=fake_distributions
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test fails on older Python versions

Medium Severity

The new test patches importlib.metadata.distributions, which does not exist on Python 3.6 and 3.7. Common CI still runs tests/test_utils.py on those versions, so the test errors when applying the patch instead of covering _generate_installed_modules.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3e86efa. Configure here.

@alexander-alderman-webb

Copy link
Copy Markdown
Collaborator

We don't need tests for private helpers. I'll close the PR and the issue.

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.

Test _generate_installed_modules

2 participants