Comments (3)
Hi @chadwhawkins !
Thanks for the kind words.
With 0.5.0 a bit of restructuring went on, and the original approach of an autouse
fixture was replaced by a test-specific setup and teardown step that should restore the original behaviors post-test.
I'm curious what led to the creation of your custom fixture - is it possible that was a workaround due to the autouse fixture misbehaving and its removal should change the need for the custom fixture?
It should be the case that if you pass the plugin's socket_enabled
fixture to a test, that should enable the network requests as you wish?
from pytest-socket.
@miketheman thanks for the reply!
I'm not sure what lead to the creation of the custom fixture as that predates my involvement in the code. Before creating this issue I tried to get socket_enabled
to work with no luck. My test setup function looked like this:
def pytest_runtest_setup():
socket_allow_hosts(allowed=["127.0.0.1", MOTO_RESOURCE_ADDRESS])
However, with a bit more investigation it looks like I need to explicitly disable everything before allowing select hosts, e.g.:
def pytest_runtest_setup():
disable_socket()
socket_allow_hosts(allowed=["127.0.0.1", MOTO_RESOURCE_ADDRESS])
I was assuming that allowing only specific hosts implied that all others would be disabled. Just wanted to confirm that's the intended pattern. Thanks!
from pytest-socket.
@chadwhawkins glad it's working out!
I usually prefer the command-line options pytest ... --disable-socket --socket-allow-hosts="127.0.0.1,..."
as a way to not have to use a custom pytest_runtest_setup()
, but see that you're using a constant for the moto address, so this approach ought to work in a similar fashion.
Closing this one out!
from pytest-socket.
Related Issues (20)
- Incompatibility with pytest-flakes? HOT 2
- 0.5.0: pytest is failing in `tests/test_async.py::test_starlette` unit HOT 4
- pytest-socket blocks retrieving other dependencies HOT 1
- Issue with sockets when trying to run Home Assistant tests HOT 2
- 0.5.1: pytest is failing in `tests/test_async.py::test_httpx_fails` unit HOT 11
- Question about asynctest and Python 3.8+ compatibility HOT 3
- Action Required: Fix Renovate Configuration
- dd-trace calls in separate thread do not fail test HOT 7
- Allow host masks HOT 2
- Allow private networks only HOT 5
- Issue with latest pytest-socket version while using testcontainers HOT 6
- ability to specify different exception instead of custom `SocketBlockedError` HOT 5
- Include tests in PyPI tarball HOT 3
- socket_allow_hosts doesn't handle AF_UNIX sockets HOT 1
- 0.4.0: tests currently failing (easy fixes) HOT 4
- Docker SDK unix socket connections blocked HOT 3
- Dependency Dashboard
- Replace pytest-flake8 with a pre-commit hook
- pytest-socket raises IndexError when used with httpx
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-socket.