responses: Cookie handling regression from 0.14.0 to 0.15.0

Environment

Using the responses library under Python 3.9.7

Steps to Reproduce

Run this test against responses 0.14.0 and against responses 0.15.0

#!/usr/bin/env python3
import sys
import requests
import responses



def main():
    with responses.RequestsMock() as fakes:
        fakes.add(responses.GET, 'https://example.com', status=200,
            adding_headers=[
                  ('Set-Cookie', 'mycookie=myvalue; path=/; secure'),
            ],
        body="Returned body",
        )

        session = requests.session()
        response = session.get('https://example.com')

        tests = {}
        tests['response-cookie'] = 'mycookie' in response.cookies
        tests['session-cookie'] = 'mycookie' in session.cookies

        failures = 0
        for testname, result in tests.items():
            if not result:
                failures += 1
            sys.stdout.write(f"Test {testname} result {result}\n")
        if failures:
            sys.stdout.write(f"{failures} of {len(tests)} failed.\n")
        else:
            sys.stdout.write(f"All {len(tests)} tests passed.\n")

        return 1 if failures else 0

if __name__ == '__main__':
    sys.exit(main())

Expected Result

Expected ‘mycookie’ to appear in both the response.cookies and the session.cookies

Actual Result

‘mycookie’ appears in both the response.cookies and the session.cookies for 0.14.0 ‘mycookie’ appears in the response.cookies but not in the session.cookies for 0.15.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I suspect the issue may be the removal of the response.close() call in RequestsMock._on_request, but I’m not sure.