Return a settings dict that works with the installed reactor. ``Crawler._apply_settings()`` checks that the installed reactor matches the settings, so tests that run the crawler in the current process may need to pass a correct :setting:`TWISTED_REACTOR` setting value when creating it.
()
| 32 | |
| 33 | |
| 34 | def get_reactor_settings() -> dict[str, Any]: |
| 35 | """Return a settings dict that works with the installed reactor. |
| 36 | |
| 37 | ``Crawler._apply_settings()`` checks that the installed reactor matches the |
| 38 | settings, so tests that run the crawler in the current process may need to |
| 39 | pass a correct :setting:`TWISTED_REACTOR` setting value when creating it. |
| 40 | """ |
| 41 | settings: dict[str, Any] = {} |
| 42 | if is_reactor_installed(): |
| 43 | if not is_asyncio_reactor_installed(): |
| 44 | settings["TWISTED_REACTOR"] = None |
| 45 | else: |
| 46 | # We are either running Scrapy tests for the reactorless mode, or |
| 47 | # running some 3rd-party library tests for the reactorless mode, or |
| 48 | # running some 3rd-party library tests without initializing a reactor |
| 49 | # properly. The first two cases are fine, but we cannot distinguish the |
| 50 | # last one from them. |
| 51 | settings["TWISTED_REACTOR_ENABLED"] = False |
| 52 | settings["DOWNLOAD_HANDLERS"] = { |
| 53 | "ftp": None, |
| 54 | "http": "scrapy.core.downloader.handlers._httpx.HttpxDownloadHandler", |
| 55 | "https": "scrapy.core.downloader.handlers._httpx.HttpxDownloadHandler", |
| 56 | } |
| 57 | return settings |
| 58 | |
| 59 | |
| 60 | def get_crawler( |
no test coverage detected