Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

disable network on pytest

# conftest.py
import pytest
import socket

_original_connect = socket.socket.connect

def patched_connect(*args, **kwargs):
    ...
    # It depends on your testing purpose
    # You may want a exception, add here
    # If you test unconnectable situations
    # it can stay like this 
    

@pytest.fixture
def enable_network():
    socket.socket.connect = _original_connect
    yield
    socket.socket.connect = patched_connect

@pytest.fixture
def disable_network():
    socket.socket.connect = patched_connect
    yield
    socket.socket.connect = _original_connect
Comment

disable network on pytest

# test_internet.py
def test_your_unconnectable_situation(disable_network):
    response = request.get('http://stackoverflow.com/')
    response.status_code == 400
Comment

PREVIOUS NEXT
Code Example
Python :: sql o que é 
Python :: Python docx title 
Python :: priting matrix using np truncating the output 
Python :: python youtube_dl custom path 
Python :: string float to round to 2dp python 
Python :: remove punctuation and special charaacters nltk 
Python :: pandas replace duplicates unique identifier 
Python :: mechanize python XE #25 
Python :: effient way to find prime no inpython 
Python :: convert integer to string python 
Python :: How do I select certain columns for regression plots 
Python :: get all non numeric columns pandas 
Python :: python urllib.request.urlretrieve with a progressbar 
Python :: can we put the object as value in a dictionary in python* 
Python :: .format() 
Python :: scipy z value to pvalue 
Python :: Linear Search Python with enumerate 
Python :: collecion.alt shopify python 
Python :: changing speak rate pyttsx 
Python :: aws chalice 
Python :: Errors while using os.makedirs() method 
Python :: enumerate zip together 
Python :: tree view width 
Python :: frozenset numbers in python 
Python :: counter and element of list for loop python 
Python :: Python NumPy atleast_3d Function Syntax 
Python :: python f strings 
Python :: Python NumPy asscalar Function Example 02 
Python :: Python NumPy repeat Function Example Working with 1D array 
Python :: __truediv__ 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =