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

Update pytest-socket setup so allow_hosts works without enable_socket #104076

Closed
wants to merge 1 commit into from

Conversation

sdb9696
Copy link
Contributor

@sdb9696 sdb9696 commented Nov 16, 2023

Proposed change

EDIT: After creating this draft PR and seeing the CI tests failing I realised a lot of tests are accessing 127.0.0.1 and not reporting errors. This PR then causes them to timeout and fail when they don't immediately get a socket exception. I managed to work around the vscode-pytest issue by using a different test adapter so closing this PR.

I'm currently unable to use the vscode-pytest plug-in to debug tests as it communicates with it's test runner via a socket to localhost, and the way pytest-socket has been configured in HA prevents the connection.

This PR proposes to remove the setup of pytest-socket in core/tests/conftest.py:pytest_runtest_setup() and set it up via pytest.ini instead. The result is that the behaviour becomes the behaviour of pytest_socket:pytest_runtest_setup() which is that --allow-hosts takes precedence over --disable-socket rather than the other way round.

The original PR that enabled pytest-socket is #55516 and included logic that was not yet in the released version so that may have influenced the decision of how to configure it.

I've searched around and no-one else seems to be complaining about this issue on HA so apologies if I've missed something obvious. There is an open issue on vscode-python where it's suggested to use allow_hosts to solve it. Whilst I appreciate this could be viewed as an issue in the vscode-python extension it does seem like the preferred behaviour in HA is to allow 127.0.0.1 anyway as the enable_socket fixture is added to quite a few tests.

N.B. The error I get from the extension is below. In a previous version of the extension it would just hang indefinitely due to a bug in it's error handling:
vscode_pytest.VSCodePytestError: Error attempting to connect to extension communication socket[vscode-pytest]: A test tried to use socket.socket.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant home-assistant bot added bugfix cla-signed core small-pr PRs with less than 30 lines. labels Nov 16, 2023
@sdb9696 sdb9696 closed this Nov 16, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2023
@sdb9696 sdb9696 deleted the update_pytest_socket branch April 4, 2024 13:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix cla-signed core small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant