mirror of https://github.com/scrapy/scrapy.git
Update test expectations for older versions of Twisted
This commit is contained in:
parent
0a4223ffeb
commit
1305cfb240
|
|
@ -2,7 +2,9 @@ from asyncio import sleep
|
|||
|
||||
import pytest
|
||||
from testfixtures import LogCapture
|
||||
from twisted import version as TWISTED_VERSION
|
||||
from twisted.internet.defer import Deferred
|
||||
from twisted.python.versions import Version
|
||||
from twisted.trial.unittest import TestCase
|
||||
|
||||
from scrapy import Spider, signals
|
||||
|
|
@ -23,6 +25,8 @@ ASYNC_GEN_ERROR_MINIMUM_SECONDS = ExecutionEngine._SLOT_HEARTBEAT_INTERVAL + 0.0
|
|||
ITEM_A = {"id": "a"}
|
||||
ITEM_B = {"id": "b"}
|
||||
|
||||
TWISTED_KEEPS_TRACEBACKS = TWISTED_VERSION >= Version("twisted", 24, 10, 0)
|
||||
|
||||
|
||||
def twisted_sleep(seconds):
|
||||
from twisted.internet import reactor
|
||||
|
|
@ -208,7 +212,10 @@ class MainTestCase(TestCase):
|
|||
with LogCapture() as log:
|
||||
await self._test_yield_seeds(yield_seeds, [])
|
||||
|
||||
assert "in yield_seeds\n raise RuntimeError" in str(log), log
|
||||
if TWISTED_KEEPS_TRACEBACKS:
|
||||
assert "in yield_seeds\n raise RuntimeError" in str(log), log
|
||||
else:
|
||||
assert "in _process_next_seed\n seed =" in str(log), log
|
||||
|
||||
@deferred_f_from_coro_f
|
||||
async def test_exception_after_yield(self):
|
||||
|
|
@ -219,7 +226,10 @@ class MainTestCase(TestCase):
|
|||
with LogCapture() as log:
|
||||
await self._test_yield_seeds(yield_seeds, [ITEM_A])
|
||||
|
||||
assert "in yield_seeds\n raise RuntimeError" in str(log), log
|
||||
if TWISTED_KEEPS_TRACEBACKS:
|
||||
assert "in yield_seeds\n raise RuntimeError" in str(log), log
|
||||
else:
|
||||
assert "in _process_next_seed\n seed =" in str(log), log
|
||||
|
||||
@deferred_f_from_coro_f
|
||||
async def test_start_url(self):
|
||||
|
|
|
|||
|
|
@ -9,7 +9,11 @@ from scrapy.exceptions import ScrapyDeprecationWarning
|
|||
from scrapy.utils.defer import deferred_f_from_coro_f, maybe_deferred_to_future
|
||||
from scrapy.utils.test import get_crawler
|
||||
|
||||
from .test_spider_yield_seeds import ASYNC_GEN_ERROR_MINIMUM_SECONDS, twisted_sleep
|
||||
from .test_spider_yield_seeds import (
|
||||
ASYNC_GEN_ERROR_MINIMUM_SECONDS,
|
||||
TWISTED_KEEPS_TRACEBACKS,
|
||||
twisted_sleep,
|
||||
)
|
||||
|
||||
ITEM_A = {"id": "a"}
|
||||
ITEM_B = {"id": "b"}
|
||||
|
|
@ -280,7 +284,10 @@ class MainTestCase(TestCase):
|
|||
with LogCapture() as log:
|
||||
await self._test_process_seeds(process_seeds, [])
|
||||
|
||||
assert "in process_seeds\n raise RuntimeError" in str(log), log
|
||||
if TWISTED_KEEPS_TRACEBACKS:
|
||||
assert "in process_seeds\n raise RuntimeError" in str(log), log
|
||||
else:
|
||||
assert "in _process_next_seed\n seed =" in str(log), log
|
||||
|
||||
@deferred_f_from_coro_f
|
||||
async def test_exception_after_yield(self):
|
||||
|
|
@ -291,4 +298,7 @@ class MainTestCase(TestCase):
|
|||
with LogCapture() as log:
|
||||
await self._test_process_seeds(process_seeds, [ITEM_A])
|
||||
|
||||
assert "in process_seeds\n raise RuntimeError" in str(log), log
|
||||
if TWISTED_KEEPS_TRACEBACKS:
|
||||
assert "in process_seeds\n raise RuntimeError" in str(log), log
|
||||
else:
|
||||
assert "in _process_next_seed\n seed =" in str(log), log
|
||||
|
|
|
|||
Loading…
Reference in New Issue