Skip to content
Discussion options

You must be logged in to vote

While we don't yet have the exact behavior you're describing (using the with context manager), you can likely accomplish this by calling the disable/enable functions directly.

Here's an example:

from pytest_socket import disable_socket, enable_socket

...

def test_something()
    # This runs with internet
	...

    disable_socket()
    # This runs without
    ...
    enable_socket()

    # This should run with 
    ...

If you'd like to submit a patch with tests that implements the context manager protocol that does this, that'd be great!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by miketheman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #325 on March 29, 2024 23:32.