httpretty
solves this problem.
Write a custom test runner where you disable only 3rd party API calls, only in your test suite.
# common/test_runner.py
import httpretty
from django.test.runner import DiscoverRunner
class CustomTestRunner(DiscoverRunner):
def run_tests(self, *args, **kwargs):
with httpretty.enabled(allow_net_connect=False):
return super().run_tests(*args, **kwargs)
add this new test runner to your settings
TEST_RUNNER = "common.test_runner.CustomTestRunner"
And from now on all external API calls have to be mocked or httpretty.errors.UnmockedError
will be raised.
Alternatively, if your project uses responses
library, responses.activate
or responses.start
should work similarly.