Allow applying @responses.activate to a class
See original GitHub issueRight now I have to apply the decorator to every method I want to mock responses in; I’d prefer to apply the decorator only to the TestCase
declaration as my TestCase
does http in every test method. This would keep requests consistent with the mock.patch behaviour.
E.g.:
@responses.activate
class CommandHandlerTestCase(unittest.TestCase):
def test_function_1(self):
responses.add(...)
def test_function_2(self):
responses.add(...)
def test_function_3(self):
responses.add(...)
Issue Analytics
- State:
- Created 9 years ago
- Reactions:14
- Comments:18 (5 by maintainers)
Top Results From Across the Web
A Utility for Mocking Out The Python Requests Library - Morioh
Responses. A utility library for mocking out the requests Python library. Note. Responses requires Python 3.7 or newer, and requests >= 2.0 ...
Read more >How can I mock requests and the response? - python
Here is a solution with requests Response class. It is cleaner IMHO. import json from ...
Read more >API Reference — HTTPretty 1.1.4 documentation
import re, json import httpretty httpretty.enable() # request passes through fake socket response = requests.get('https://httpbin.org') httpretty.disable() ...
Read more >Activate Early Access class teams created by your IT Admin
Follow these steps to activate your class teams and give students access after ... These instructions apply to you if the IT Admin...
Read more >Mocking Python Requests with Responses - cra mr
If this post was valuable and you'd like me to restore it, let me know! ... @responses.activate def test_yipit_api_returning_deals(): ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just wanted to share how I solved this, using a mixin class, that uses TestCase setUp and tearDown to call the start, stop and reset methods of
responses
, and adds an (optional) default response. The one I use and maintain is here: https://gist.github.com/asfaltboy/bebd2c6943c34b0b27a7e3060448049bHere’s the “gist” of it (no pun intended):
Then use in a
TestCase
:@dcramer let me know if you would like a PR of this, i.e with tests and docs
Update: Updated to support versions > 0.5.1
Even if this mixing doesn’t end up in the library, it should at least be in the documentation.