Skip to content

Commit

Permalink
tests: enable socket access for responses 0.24+ compatibility (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem authored Nov 3, 2023
1 parent 5f4d87b commit 74df799
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def coordinator(hass, config_entry, alarm_device):


@pytest.fixture(scope="function")
def client():
def client(socket_enabled):
"""Creates an instance of `ElmoClient` which emulates the behavior of a real client for
testing purposes.
Expand All @@ -105,6 +105,18 @@ def client():
Use it for integration tests where a realistic interaction with the `ElmoClient` is required
without actual external calls.
NOTE: `socket_enabled` fixture from `pytest-socket` is required for this fixture to work. After
a change in `responses` (https://github.com/getsentry/responses/pull/685) available from
release 0.24.0 onwards, any call to `ElmoClient` indirectly create a dummy socket:
>>> socket.socket(socket.AF_INET, socket.SOCK_STREAM)
forcing `pytest-socket` to fail with the following error:
>>> pytest_socket.SocketBlockedError: A test tried to use socket.socket.
Keep loading `socket_enabled` fixture until this issue is handled better in `responses` library.
"""
client = ElmoClient(base_url="https://example.com", domain="domain")
with responses.RequestsMock(assert_all_requests_are_fired=False) as server:
Expand Down

0 comments on commit 74df799

Please sign in to comment.