Skip to content

A test tried to use socket.socket.connect() with host "localhost" (allowed: "127.0.0.1"). #178

@alexschwantes

Description

@alexschwantes

Environment:

Operating System: win10
Development Environment: Visual Studio Code
Python Version: 3.12.1
Pytest Version: 7.4.3
pytest-socket: 0.6.0
pytest-homeassistant-custom-component: 0.13.88

Steps to Reproduce:

Clone https://github.com/watkins-matt/home-assistant-google-keep-sync
setup new venv and try to run pytest within vscode

Expected Behavior:

The test suite runs without any issues.

Actual Behavior:

The test suite fails to start, and the following error is displayed:

vscode_pytest.VSCodePytestError: Error attempting to connect to extension communication socket[vscode-pytest]: A test tried to use socket.socket.connect() with host "localhost" (allowed: "127.0.0.1").

Additional Information:

Tried the following without any luck:

  • @pytest.mark.allow_hosts(['127.0.0.1', 'localhost'])
  • edit setup.cfg:
    [tool:pytest]
    addopts = --allow-hosts=127.0.0.1,localhost
  • edit pytest.ini:
    [pytest]
    addopts = --allow-hosts=127.0.0.1,localhost
  • conftest.py
    pytest_socket.socket_allow_hosts(["127.0.0.1","localhost"])
  • settings.json
    tried disabling vscode experiments with "python.experiments.enabled": false

Suggested Fix

The aparent source of the issue was found in a separate issue #171 (comment)

In plugin.py changing on line 144 change
pytest_socket.socket_allow_hosts(["127.0.0.1"]) to
pytest_socket.socket_allow_hosts(["127.0.0.1", "localhost"])
resolves the issue.

It would seem that this setting can't be overridden by these other settings listed above, only by allowing this plugin to accept hosts from localhost in addition to 127.0.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions