Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

added unittest for scrapy shell command and fixed flake8 error

Alexc2de9372a271
diff --git a/scrapy/utils/reactor.py b/scrapy/utils/reactor.py
index 532d7b0d0..e6b8de292 100644
--- a/scrapy/utils/reactor.py
+++ b/scrapy/utils/reactor.py
@@ -80,6 +80,7 @@ def install_reactor(reactor_path, event_loop_path=None):
with suppress(error.ReactorAlreadyInstalledError):
installer()
+
def set_asyncio_event_loop(event_loop_path):
"""Sets and returns the event loop with specified import path."""
policy = get_asyncio_event_loop_policy()
diff --git a/tests/test_command_shell.py b/tests/test_command_shell.py
index 33c98ad69..f06a02f5f 100644
--- a/tests/test_command_shell.py
+++ b/tests/test_command_shell.py
@@ -115,3 +115,14 @@ class ShellTest(ProcessTest, SiteTest, unittest.TestCase):
errcode, out, err = yield self.execute([url, '-c', 'item'], check_code=False)
self.assertEqual(errcode, 1, out or err)
self.assertIn(b'DNS lookup failed', err)
+
+ @defer.inlineCallbacks
+ def test_shell_fetch_async(self):
+ reactor_path = "twisted.internet.asyncioreactor.AsyncioSelectorReactor"
+ url = self.url('/html')
+ code = f"fetch('{url}')"
+ args = ["-c", code, "--set", f"TWISTED_REACTOR={reactor_path}"]
+ _, _, err = yield self.execute(args, check_code=True)
+ self.assertNotIn(
+ b"RuntimeError: There is no current event loop in thread", err
+ )