Last active
February 22, 2019 14:24
-
-
Save asfaltboy/bebd2c6943c34b0b27a7e3060448049b to your computer and use it in GitHub Desktop.
A responses TestCase Mixin
This file contains 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
""" | |
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