Created
February 3, 2015 22:23
-
-
Save 0xbepresent/3ff42213dffcf0981e83 to your computer and use it in GitHub Desktop.
Mock Get Requests in all Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from mock import patch | |
from django.test.runner import DiscoverRunner | |
class CustomTestRunner(DiscoverRunner): | |
"""Custom test runner""" | |
def __init__(self, *args, **kwargs): | |
super(CustomTestRunner, self).__init__(*args, **kwargs) | |
# Mock Get Requests, return None. | |
self.patch_get_requests = patch.object(requests, 'get', return_value=None) | |
def setup_test_environment(self, **kwargs): | |
super(CustomTestRunner, self).setup_test_environment(**kwargs) | |
self.patch_get_requests.start() # Start the mock requests | |
def teardown_test_environment(self, **kwargs): | |
super(CustomTestRunner, self).teardown_test_environment(**kwargs) | |
self.patch_get_requests.stop() # Stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment