mirror of https://github.com/scrapy/scrapy.git
test_crawl: make mock server print a line when ready, and wait for that line to start tests, instead of waiting for an arbitrary time
This commit is contained in:
parent
ce177fa5bc
commit
626331b865
|
|
@ -77,7 +77,12 @@ class Root(Resource):
|
|||
return 'Scrapy mock HTTP server\n'
|
||||
|
||||
|
||||
root = Root()
|
||||
factory = Site(root)
|
||||
reactor.listenTCP(8998, factory)
|
||||
reactor.run()
|
||||
if __name__ == "__main__":
|
||||
root = Root()
|
||||
factory = Site(root)
|
||||
port = reactor.listenTCP(8998, factory, interface="127.0.0.1")
|
||||
def print_listening():
|
||||
h = port.getHost()
|
||||
print "Mock server running at http://%s:%d" % (h.host, h.port)
|
||||
reactor.callWhenRunning(print_listening)
|
||||
reactor.run()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import sys, time
|
||||
from twisted.internet import defer
|
||||
from twisted.trial.unittest import TestCase, SkipTest
|
||||
from subprocess import Popen
|
||||
from subprocess import Popen, PIPE
|
||||
from scrapy.spider import BaseSpider
|
||||
from scrapy.http import Request
|
||||
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
|
||||
|
|
@ -32,8 +32,8 @@ def docrawl(spider, settings=None):
|
|||
class CrawlTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.proc = Popen([sys.executable, '-m', 'scrapy.tests.mockserver'])
|
||||
time.sleep(0.5)
|
||||
self.proc = Popen([sys.executable, '-u', '-m', 'scrapy.tests.mockserver'], stdout=PIPE)
|
||||
self.proc.stdout.readline()
|
||||
|
||||
def tearDown(self):
|
||||
self.proc.kill()
|
||||
|
|
|
|||
Loading…
Reference in New Issue