1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-25 08:03:48 +00:00

silence irrelevant (and confusing) errors generated in tests by signals left active after engine tests run - we should really rewrite engine tests asap

This commit is contained in:
Pablo Hoffman 2010-08-09 13:24:22 -03:00
parent bb2e0de7da
commit a08e62a25d
2 changed files with 17 additions and 1 deletions

View File

@ -101,6 +101,14 @@ class CrawlingSession(object):
scrapymanager.start()
self.port.stopListening()
self.wasrun = True
# FIXME: extremly ugly hack to avoid propagating errors to other
# stats because of living signals. This whole test_engine.py should
# be rewritten from scratch actually.
from scrapy.utils.signal import disconnect_all
from scrapy.stats import signals as stats_signals
disconnect_all(stats_signals.stats_spider_opened)
disconnect_all(stats_signals.stats_spider_closing)
disconnect_all(stats_signals.stats_spider_closed)
def geturl(self, path):
return "http://localhost:%s%s" % (self.portno, path)

View File

@ -2,7 +2,8 @@
from twisted.python.failure import Failure
from scrapy.xlib.pydispatch.dispatcher import Any, Anonymous, liveReceivers, getAllReceivers
from scrapy.xlib.pydispatch.dispatcher import Any, Anonymous, liveReceivers, \
getAllReceivers, disconnect
from scrapy.xlib.pydispatch.robustapply import robustApply
from scrapy import log
@ -27,3 +28,10 @@ def send_catch_log(signal=Any, sender=Anonymous, *arguments, **named):
result = response
responses.append((receiver, result))
return responses
def disconnect_all(signal=Any, sender=Any):
"""Disconnect all signal handlers. Useful for cleaning up after running
tests
"""
for receiver in liveReceivers(getAllReceivers(sender, signal)):
disconnect(receiver, signal=signal, sender=sender)