make sure the mockserver forked from tests uses the current installation of scrapy, not the system one

This commit is contained in:
Pablo Hoffman 2013-05-06 17:27:59 -03:00
parent cf4d4bc094
commit 14e7121674
2 changed files with 11 additions and 2 deletions

View File

@ -5,7 +5,7 @@ from subprocess import Popen, PIPE
from scrapy.spider import BaseSpider
from scrapy.http import Request
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.utils.test import get_crawler
from scrapy.utils.test import get_crawler, get_testenv
class FollowAllSpider(BaseSpider):
@ -52,7 +52,8 @@ def docrawl(spider, settings=None):
class CrawlTestCase(TestCase):
def setUp(self):
self.proc = Popen([sys.executable, '-u', '-m', 'scrapy.tests.mockserver'], stdout=PIPE)
self.proc = Popen([sys.executable, '-u', '-m', 'scrapy.tests.mockserver'],
stdout=PIPE, env=get_testenv())
self.proc.stdout.readline()
def tearDown(self):

View File

@ -67,6 +67,14 @@ def get_pythonpath():
scrapy_path = __import__('scrapy').__path__[0]
return os.path.dirname(scrapy_path) + sep + os.environ.get('PYTHONPATH', '')
def get_testenv():
"""Return a OS environment dict suitable to fork processes that need to import
this installation of Scrapy, instead of a system installed one.
"""
env = os.environ.copy()
env['PYTHONPATH'] = get_pythonpath()
return env
def assert_samelines(testcase, text1, text2, msg=None):
"""Asserts text1 and text2 have the same lines, ignoring differences in
line endings between platforms