Skip to content

Comments

tests: fix mock UPnP#12

Merged
clementperon merged 1 commit intomainfrom
fix_upnp
Feb 18, 2026
Merged

tests: fix mock UPnP#12
clementperon merged 1 commit intomainfrom
fix_upnp

Conversation

@clementperon
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 18, 2026 08:59
@clementperon clementperon merged commit 81a1175 into main Feb 18, 2026
8 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the UPnP discovery mocking in the test_discovery_wrapper test to properly prevent network access during unit testing. The changes add a socket forbid guardrail and corresponding error handling.

Changes:

  • Added mock for UpnpDiscoveryGateway to prevent real UPnP discovery during testing
  • Added socket forbid guardrail to fail fast if the test accidentally attempts network access
  • Added error handling in upnp_gateway.py to gracefully handle socket errors (including mock-raised errors)

Reviewed changes

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

File Description
tests/test_compat_wrappers.py Updated test to mock both mDNS and UPnP gateways, added socket forbid guardrail, and improved import/naming clarity
src/devialetctl/infrastructure/upnp_gateway.py Added try-except to handle OSError on socket.sendto, allowing graceful degradation when sockets are unavailable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


monkeypatch.setattr("devialetctl.infrastructure.upnp_gateway.socket.socket", _forbid_socket)
monkeypatch.setattr(discovery_module, "MdnsDiscoveryGateway", FakeMdnsGateway)
monkeypatch.setattr(discovery_module, "UpnpDiscoveryGateway", lambda: FakeUpnpGateway())
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The UpnpDiscoveryGateway mock uses an inconsistent pattern compared to MdnsDiscoveryGateway. Line 63 patches MdnsDiscoveryGateway with the class directly (FakeMdnsGateway), but this line wraps FakeUpnpGateway in a lambda. For consistency and correctness, it should be: monkeypatch.setattr(discovery_module, "UpnpDiscoveryGateway", FakeUpnpGateway) without the lambda wrapper.

Suggested change
monkeypatch.setattr(discovery_module, "UpnpDiscoveryGateway", lambda: FakeUpnpGateway())
monkeypatch.setattr(discovery_module, "UpnpDiscoveryGateway", FakeUpnpGateway)

Copilot uses AI. Check for mistakes.
@clementperon clementperon deleted the fix_upnp branch February 20, 2026 11:22
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.

1 participant