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

fix: allow ip hosts and hostnames #275

Merged
merged 3 commits into from Jan 16, 2024

Conversation

magnasilvar
Copy link
Contributor

@magnasilvar magnasilvar commented Nov 13, 2023

TL;DR

VS Code users at my company are facing a bug that at first sight seemed to be linked to the IDE (because our unit tests run from the command line), but which in reality is related to a pytest-socket bug (highlighted by the creation of a socket on the hostname localhost by the vscode-python extension).


Problem

Our following code from conftest.py makes it impossible to use the Testing tab in VS Code (no matter which unit test is run).

# ...
from pytest_socket import socket_allow_hosts
# ...

# ...
def pytest_runtest_setup():
    socket_allow_hosts(
        allowed=["localhost", "127.0.0.1", "::1"], allow_unix_socket=True
    )
# ...

Error observed:

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

Why?

The error message from pytest-socket is wrong:

  • localhost is not compared to localhost,127.0.0.1 and ::1.
  • But to 127.0.0.1,127.0.0.1 and ::1.

This is because the allowed hosts used for comparison are previously converted to IP addresses. Therefore, a comparison with a host that is not an IP address can never succeed.


Affected versions

pytest-socket version Bug presence
0.6.0 Yes
0.5.1 No

Diagnostic data

VS Code info

Version: 1.84.2 (Universal)
Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
Date: 2023-11-09T10:52:33.687Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 23.1.0

Extension version

Name: Python
Id: ms-python.python
Version: 2023.20.0
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python

Related issues / PR

This PR resolves:

@magnasilvar
Copy link
Contributor Author

Hi @miketheman 👋 Can you take a look when you have time? 🙏

Copy link

codeclimate bot commented Jan 5, 2024

Code Climate has analyzed commit 27cff82 and detected 0 issues on this pull request.

View more on Code Climate.

@magnasilvar
Copy link
Contributor Author

Happy New Year @miketheman 🎉
From the reactions on this PR, it seems that many people have the same issue, is it possible for you to review it? 🙏

@miketheman miketheman merged commit fc15fee into miketheman:main Jan 16, 2024
18 checks passed
@miketheman miketheman added the bug Something isn't working label Jan 16, 2024
@miketheman
Copy link
Owner

Thanks @magnasilvar - I'll likely cut a fresh release in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants