diff --git a/scrapy/commands/check.py b/scrapy/commands/check.py index b8af0d55b..b1fd0b76e 100644 --- a/scrapy/commands/check.py +++ b/scrapy/commands/check.py @@ -53,8 +53,8 @@ def _report_crawl_errors( up as an error in *result*, instead of being silently discarded.""" class CrawlTestCase(TestCase): - def runTest(self) -> None: - pass + # unittest requires a test method, but this one is only reported, never run. + runTest = staticmethod(lambda: None) def __str__(self) -> str: return f"[{spidername}] crawl" @@ -72,7 +72,8 @@ def _report_crawl_errors( report(failure.value) crawl.addErrback(on_failure) - elif isinstance(crawl, asyncio.Task): + else: + assert isinstance(crawl, asyncio.Task) def on_done(task: asyncio.Task[None]) -> None: if not task.cancelled() and (exception := task.exception()) is not None: diff --git a/tests/test_command_check.py b/tests/test_command_check.py index ffa787c5f..8e183c1b6 100644 --- a/tests/test_command_check.py +++ b/tests/test_command_check.py @@ -81,17 +81,22 @@ class CheckSpider(scrapy.Spider): """ self._test_contract(proj_path, contracts, parse_def, use_reactor=False) - @pytest.mark.parametrize("use_reactor", [True, False]) - def test_check_crawl_error(self, proj_path: Path, use_reactor: bool) -> None: + @pytest.mark.parametrize( + "settings", + [ + "", + "TWISTED_REACTOR_ENABLED = False\n", + "FORCE_CRAWLER_PROCESS = True\n", + ], + ids=["async", "no_reactor", "crawler_process"], + ) + def test_check_crawl_error(self, proj_path: Path, settings: str) -> None: self._write_contract(proj_path, "@returns requests 0", "pass") self._append_settings( proj_path / self.project_name, - "\nITEM_PIPELINES = {'nonexistent.module.Pipeline': 300}\n", + f"\nITEM_PIPELINES = {{'nonexistent.module.Pipeline': 300}}\n{settings}", ) - args = ["check"] - if not use_reactor: - args += ["-s", "TWISTED_REACTOR_ENABLED=False"] - ret, _, err = proc(*args, cwd=proj_path) + ret, _, err = proc("check", cwd=proj_path) assert f"[{self.spider_name}] crawl" in err assert "ModuleNotFoundError" in err assert "FAILED (errors=1)" in err