Incorrect setUp example in README
See original GitHub issueEnvironment
There is a bug in the README doc in the Responses inside a unittest setUp()
section. At the moment the docs say that you should add stop BEFORE reset to the cleanUp functions but since cleanups are run in reversed order this is incorrect. In this configuration you won’t be able to check if every mock was called since the reset will reset the responses mock’s list and stop
won’t have anything to check. You can check this out by investigating the unittest.TestCase class.
`
def doCleanups(self):
outcome = self._outcome or _Outcome()
while self._cleanups:
function, args, kwargs = self._cleanups.pop()
with outcome.testPartExecutor(self):
function(*args, **kwargs)
# return this for backwards compatibility
# even though we no longer us it internally
return outcome.success
`
As you can see there is a .pop()
call that pop the LAST element from the list.
Steps to Reproduce
- You can reproduce this by simply doing a TestCase with 1 mocked response and changing the order of the functions added to cleanups
Expected Result
The reset should be added to cleanups BEFORE the stop function. The docs should be:
`
def setUp():
self.responses = responses.RequestsMock()
self.responses.start()
# self.responses.add(...)
self.addCleanup(self.responses.reset)
self.addCleanup(self.responses.stop)
def test_api(self):
self.responses.add(
responses.GET, 'http://twitter.com/api/1/foobar',
body='{}', status=200,
content_type='application/json')
resp = requests.get('http://twitter.com/api/1/foobar')
assert resp.status_code == 200
`
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Basic writing and formatting syntax - GitHub Docs
Create sophisticated formatting for your prose and code on GitHub with simple syntax.
Read more >How to Write a Good README File for Your GitHub Project
Provide instructions and examples so users/contributors can use the project. This will make it easy for them in case they encounter a problem...
Read more >Professional README Guide | The Full-Stack Blog
To help you create high-quality READMEs from the start, this guide outlines some basic best practices for creating them.
Read more >Two README files, Doxygen picks the wrong one
Fixed moving the subproject's Doxyfile in its own directory: Project root Doxyfile1 README.md Subdir Doxyfile2 README.md.
Read more >README File – Everything you Need to Know - Great Learning
For example, if there exists a need to install software to run the project. Then the version of the software and technical configurations...
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
@itsdkey glad it helps 😃
okay, this can be good 😄