Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alexschwantes opened this issue Jan 12, 2024 · 1 comment

Comments

@alexschwantes
Copy link

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

@Xyaren
Copy link

Xyaren commented Apr 18, 2024

Possibly solved by a new version of vscode: microsoft/vscode-python#22383

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

No branches or pull requests

2 participants