Scrapy, a fast high-level web crawling & scraping framework for Python.
Fix limiting subprocess run time in tests. (#6933)
Andrey Rakhmatullin8d82e7bd2731
diff --git a/tests/test_command_runspider.py b/tests/test_command_runspider.pyindex c1a6d9b18..0c12a59f7 100644--- a/tests/test_command_runspider.py+++ b/tests/test_command_runspider.py@@ -112,6 +112,11 @@ class MySpider(scrapy.Spider):name = 'myspider'start_urls = ['http://localhost:12345']+ custom_settings = {+ "ROBOTSTXT_OBEY": False,+ "RETRY_ENABLED": False,+ }+def parse(self, response):return {'test': 'value'}"""diff --git a/tests/test_commands.py b/tests/test_commands.pyindex 1b36fbb31..a749de9fe 100644--- a/tests/test_commands.py+++ b/tests/test_commands.py@@ -9,10 +9,11 @@ from io import StringIOfrom pathlib import Pathfrom shutil import rmtreefrom tempfile import TemporaryFile, mkdtemp-from threading import Timerfrom typing import TYPE_CHECKING, Anyfrom unittest import mock+import pytest+import scrapyfrom scrapy.cmdline import _pop_command_name, _print_unknown_command_msgfrom scrapy.commands import ScrapyCommand, ScrapyHelpFormatter, view@@ -100,17 +101,12 @@ class TestProjectBase:**popen_kwargs,)- def kill_proc():+ try:+ stdout, stderr = p.communicate(timeout=15)+ except subprocess.TimeoutExpired:p.kill()p.communicate()- raise AssertionError("Command took too much time to complete")-- timer = Timer(15, kill_proc)- try:- timer.start()- stdout, stderr = p.communicate()- finally:- timer.cancel()+ pytest.fail("Command took too much time to complete")return p, to_unicode(stdout), to_unicode(stderr)diff --git a/tests/test_engine.py b/tests/test_engine.pyindex 9a3075f31..7612c6200 100644--- a/tests/test_engine.py+++ b/tests/test_engine.py@@ -17,7 +17,6 @@ from collections import defaultdictfrom dataclasses import dataclassfrom logging import DEBUGfrom pathlib import Path-from threading import Timerfrom unittest.mock import Mockfrom urllib.parse import urlparse@@ -495,17 +494,12 @@ class TestEngine(TestEngineBase):stderr=subprocess.PIPE,)- def kill_proc():+ try:+ _, stderr = p.communicate(timeout=3)+ except subprocess.TimeoutExpired:p.kill()p.communicate()- raise AssertionError("Command took too much time to complete")-- timer = Timer(15, kill_proc)- try:- timer.start()- _, stderr = p.communicate()- finally:- timer.cancel()+ pytest.fail("Command took too much time to complete")stderr_str = stderr.decode("utf-8")assert "AttributeError" not in stderr_str, stderr_str