question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect setUp example in README

See original GitHub issue

Environment

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

  1. 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:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
beliaev-maksimcommented, Dec 1, 2021

@itsdkey glad it helps 😃

0reactions
itsdkeycommented, Dec 1, 2021

okay, this can be good 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found