Skip to content

refactor/fix: move logic into setup phase and correct order - #88

Merged
miketheman merged 5 commits into
mainfrom
miketheman/refactor-autouse
Dec 22, 2021
Merged

miketheman merged 5 commits into
mainfrom
miketheman/refactor-autouse

Conversation

@miketheman

@miketheman miketheman commented Dec 20, 2021 •

Copy link
Copy Markdown
Owner

When the plugin started out, I didn't know how to use the
runtest_setup phase, so I used an automatically-used fixture.
I've now removed the fixture, which may have had unintended side effects with other plugins or test suites.

I've also changed the ordering, to be more inline with the expected behaviors, as I laid out in https://github.com/miketheman/pytest-socket/discussions/81#discussion-3670981

I've added a bunch of tests that express the desired precedence behavior in a test module tests/test_precedence.py and all the existing tests pass as well 🎉 .

This, and a few other bits, should lead to an 0.50.0 release.

Signed-off-by: Mike Fiedler [email protected]

@miketheman miketheman added the chore General maintenance items label Dec 20, 2021
@miketheman miketheman self-assigned this Dec 20, 2021
@miketheman miketheman added this to the 0.50.0 milestone Dec 20, 2021
@miketheman
miketheman force-pushed the miketheman/refactor-autouse branch from cff29a1 to 8f5fb28 Compare December 20, 2021 22:14
Comment thread pytest_socket.py Resolved
@miketheman
miketheman force-pushed the miketheman/refactor-autouse branch from 430ba8e to fae0c2a Compare December 21, 2021 00:33
@miketheman
miketheman marked this pull request as draft December 21, 2021 16:39
@miketheman
miketheman force-pushed the miketheman/refactor-autouse branch from fae0c2a to 1b33d25 Compare December 21, 2021 16:50
When the plugin started out, I didn't know how to use the
`runtest_setup` phase, so I used an automatically-used fixture.

Once the hook usage was introduced, I can now consolidate a lot of the
behavior logic ion one place.

Signed-off-by: Mike Fiedler <[email protected]>
May duplicate some of the other tests, but I wanted to make sure this
was clear.
I may refactor other tests later - it's unclear how to measure how many
times a line is hit right now.

Signed-off-by: Mike Fiedler <[email protected]>
The previous configuration allowed for `allow-hosts` to be passed
without `--disable-socket` to implicitly activate blocking.

This was confusing and inconsistent so we now require it to enable the
global behavior.

This introduces a little more complexity to the setup method, but is
more clear as to what is actually happening.

Signed-off-by: Mike Fiedler <[email protected]>
@miketheman
miketheman force-pushed the miketheman/refactor-autouse branch from 1b33d25 to e4fff1a Compare December 21, 2021 21:28
@miketheman
miketheman force-pushed the miketheman/refactor-autouse branch from 103682a to d99a622 Compare December 21, 2021 23:21
Signed-off-by: Mike Fiedler <[email protected]>
@qlty-cloud-legacy

Copy link
Copy Markdown

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

View more on Code Climate.

@miketheman
miketheman marked this pull request as ready for review December 22, 2021 19:44
@miketheman miketheman changed the title refactor: move logic into setup phase refactor/fix: move logic into setup phase and correct order Dec 22, 2021
@miketheman
miketheman merged commit 224124a into main Dec 22, 2021
@miketheman
miketheman deleted the miketheman/refactor-autouse branch December 22, 2021 20:01
altendky added a commit to altendky/hamster-mcp that referenced this pull request Mar 26, 2026
pytest-socket and pytest-homeassistant-custom-component both register
pytest_runtest_setup hooks via entry points.  Entry-point discovery
order depends on filesystem iteration of site-packages, which is
non-deterministic on Linux.  When pytest-socket's hook runs before the
HA plugin's hook, enable_socket() is called first and then immediately
overridden by disable_socket(), causing SocketBlockedError.

Replace the bare enable_socket marker with usefixtures('socket_enabled').
The fixture runs during fixture setup (after all hooks), so it
deterministically re-enables sockets regardless of hook ordering.

This matches how HA core itself avoids the problem (e.g. the
hass_client and hass_ws_client fixtures explicitly depend on
socket_enabled).

Upstream references:
- miketheman/pytest-socket#88
- miketheman/pytest-socket#125
- MatthewFlamm/pytest-homeassistant-custom-component#154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore General maintenance items

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant