Skip to content

PYTHON-5727 Add tests for __main__ blocks#2936

Merged
aclark4life merged 6 commits into
mongodb:mainfrom
aclark4life:PYTHON-5727-main-tests
Jul 22, 2026
Merged

PYTHON-5727 Add tests for __main__ blocks#2936
aclark4life merged 6 commits into
mongodb:mainfrom
aclark4life:PYTHON-5727-main-tests

Conversation

@aclark4life

@aclark4life aclark4life commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

PYTHON-5727

Changes in this PR

Adds test coverage for the previously untested __main__ block in pymongo/uri_parser.py.

A new TestMainBlock class in test/test_uri_parser.py launches the module as a script via subprocess (python -m pymongo.uri_parser <uri>) and covers both branches:

  • a valid URI is parsed and pretty-printed to stdout
  • an invalid URI is caught and its error message printed

Test Plan

  • python -m pytest test/test_uri_parser.py::TestMainBlock test/test_daemon.py::TestMainBlock -v passes.
  • Both cases assert a clean (0) exit code.
  • The new tests exercise the __main__ block end-to-end through a real subprocess so coverage.py subprocess measurement will capture it.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)? N/A — test-only change.
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s). N/A

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds end-to-end test coverage for the pymongo.uri_parser module’s __main__ block by executing it as a real module in a subprocess, ensuring both the success path (pretty-printed parsed result) and the handled error path (InvalidURI) are exercised.

Changes:

  • Add subprocess-based tests that run python -m pymongo.uri_parser <uri> and assert expected stdout content.
  • Cover both valid URI parsing output and invalid URI error message output while confirming exit code 0.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread test/test_uri_parser.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@aclark4life
aclark4life marked this pull request as ready for review July 22, 2026 17:02
@aclark4life
aclark4life requested a review from a team as a code owner July 22, 2026 17:02
@aclark4life
aclark4life requested a review from blink1073 July 22, 2026 17:02

@blink1073 blink1073 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@blink1073

Copy link
Copy Markdown
Member

These look unrelated:

FAILED test/asynchronous/test_discovery_and_monitoring.py::TestUnifiedHelloTimeout::test_Driver_extends_timeout_while_streaming - AssertionError: 2 != 0 : expected 0 not {'serverDescriptionChangedEvent': {'newDescription': {'type': 'Unknown'}}}
FAILED test/test_discovery_and_monitoring.py::TestUnifiedHelloTimeout::test_Driver_extends_timeout_while_streaming - AssertionError: 2 != 0 : expected 0 not {'serverDescriptionChangedEvent': {'newDescription': {'type': 'Unknown'}}}

@aclark4life
aclark4life merged commit f26360d into mongodb:main Jul 22, 2026
75 of 85 checks passed
@aclark4life
aclark4life deleted the PYTHON-5727-main-tests branch July 22, 2026 20:34
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.

4 participants