-
Notifications
You must be signed in to change notification settings - Fork 12
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
pytest_socket.SocketBlockedError: A test tried to use socket.socket. #154
Comments
See #96, which is probably related. Are you defining any fixtures in your test? It looks like it is failing during setup of the test. |
@MatthewFlamm, hello. This issue is relevant for tests in https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/tree/master/tests without any modifications at Windows machines. Linux machines is not affected. Looks like Windows is using pytest-homeassistant-custom-component/src/pytest_homeassistant_custom_component/plugins.py Line 153 in ee2dc56
(after commenting just this line all works well by obvious reason) |
If this is indeed a Windows difference, homeassistant core does not support or test on Windows, so this is use case is unsupported. You may need to use a fixture to enable the needed socket, but I am not familiar with this. |
The problem is not in HomeAssistant code base, but in Special fixture for enabling socket looks promising, but is should be loaded in |
This package simply extracts the testing from homeassistant core with very light modifications for ease of use. If running in Windows isn't supported in homeassistant core, then it won't be supported here either. We don't mess with hass fixture in this package for this reason. |
If Windows is not suppose to work, any advice on the dev environment? Simply wsl? Or inside the devcontainer of the official home assistance code dev environment? The file structure come out from cookiecutter template seems not so ideal to use in Home assistant core devcontainer. Thanks for pointing the right direction to beginner as me:) |
@fishy242, for tests from Windows I'm using dev container like this (is not advice, but it is my way to run tests while using Windows): FROM python:3.9.10
ENV PIP_DISABLE_ROOT_WARNING=1
RUN python -m pip install --upgrade pip
COPY requirements_test.txt requirements.txt
RUN pip install -r requirements.txt
VOLUME /app
WORKDIR /app
ENV NO_COLOR=yes_please
ENV LANG=C
CMD ["python", "-m", "pytest"] and using project root as |
Now I do coding and testing in WSL, I think that’s good enough for me at this moment. Thanks all the help from here! |
I'm stuck with this error as well... on MacOS though...
|
I have run into this issue with a DevContainer on Windows. The tests run from the CLI but fail in VS Code. The solution for me was to comment out the code which blocks sockets. I've created a branch which you can test by replacing the
I'm not sure what the permanent solution to this would be. |
Also happening within a remote dev-container running in docker on ubuntu. Workaround for me is the following from pytest_socket import enable_socket, disable_socket, socket_allow_hosts
import pytest
@pytest.hookimpl(trylast=True)
def pytest_runtest_setup():
enable_socket()
socket_allow_hosts(["127.0.0.1", "localhost", "::1"], allow_unix_socket=True) There is an update on the original issue from vscode: |
Hi,
I shall say at the very beginning, I am new to the home assistant custom component development and new to python too, so I think I get something missing but I cannot find any result from google.
What I have done so far is just clone this repo, setup a venv by
python -m venv venv
, activate the venv and then topip install pytest-homeassistant-custom-componet
. Every things look OK so far. But when I try to runpytest
in this repo, I get the following errorI get the same error even on my dummy test which just contain
assert(True)
. Apparently I didn't try to open any socket. How can I get rid of this issue?Your help and advice would be much appreciated. Thanks!
The text was updated successfully, but these errors were encountered: