Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequestsMock doesn't catch requests inside loop.run_in_executor(None, ...) #703

Open
andrei-shabanski opened this issue Jan 31, 2024 · 0 comments
Labels

Comments

@andrei-shabanski
Copy link

andrei-shabanski commented Jan 31, 2024

Describe the bug

RequestsMock doesn't catch requests that are sent inside the default asyncio executor. As a result, real HTTP requests are sent.

Additional context

Python 3.9 - 3.11

Version of responses

0.24.1

Steps to Reproduce

import asyncio
import responses
import requests

def send_request():
    # Here a real HTTP request will be sent
    response = requests.get('https://example.com/')
    print(response.content)

def main():
    with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
        rsps.get('https://example.com/', body='test')

        loop = asyncio.get_event_loop()
        loop.run_in_executor(None, send_request)
        # but   send_request()  works correct and DOES NOT send a real HTTP request

main()

Expected Result

test should be printed.

Actual Result

A real HTTP request is sent to https://example.com/, and a page body b'<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>.... is printed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

3 participants