Skip to content

Instantly share code, notes, and snippets.

@asfaltboy
Last active February 22, 2019 14:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asfaltboy/bebd2c6943c34b0b27a7e3060448049b to your computer and use it in GitHub Desktop.
Save asfaltboy/bebd2c6943c34b0b27a7e3060448049b to your computer and use it in GitHub Desktop.
A responses TestCase Mixin
"""
A unittest.TestCase mixin that allows using the
responses (https://pypi.python.org/pypi/responses/) package in tests.
Usage
-----
Install responses with `pip install responses`.
Add `ResponsesMixin` to your `TestCase` parent classes instead of using
the `@responses.activate` decorator; for details see issue here:
https://github.com/getsentry/responses/issues/31
"""
import responses
class ResponsesMixin(object):
def setUp(self):
assert responses, 'responses package required to use ReponsesMixin'
responses.start()
self.add_default_response()
super(ResponsesMixin, self).setUp()
def tearDown(self):
super(ResponsesMixin, self).tearDown()
responses.stop()
responses.reset()
def add_default_response(self):
""" Override to add default response/s for all test in this TestCase """
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment