Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Fix Feedexport test in Windows by using proper file URI

Jakob de Maeyer034152961d18
diff --git a/tests/test_feedexport.py b/tests/test_feedexport.py
index 2b57449d9..6eefa14bf 100644
--- a/tests/test_feedexport.py
+++ b/tests/test_feedexport.py
@@ -2,11 +2,12 @@ from __future__ import absolute_import
import os
import csv
import json
+import warnings
from io import BytesIO
import tempfile
import shutil
-from six.moves.urllib.parse import urlparse
-import warnings
+from six.moves.urllib.parse import urljoin, urlparse
+from six.moves.urllib.request import pathname2url
from zope.interface.verify import verifyObject
from twisted.trial import unittest
@@ -226,9 +227,10 @@ class FeedExportTest(unittest.TestCase):
def run_and_export(self, spider_cls, settings=None):
""" Run spider with specified settings; return exported data. """
tmpdir = tempfile.mkdtemp()
- res_name = tmpdir + '/res'
+ res_path = os.path.join(tmpdir, 'res')
+ res_uri = urljoin('file:', pathname2url(res_path))
defaults = {
- 'FEED_URI': 'file://' + res_name,
+ 'FEED_URI': res_uri,
'FEED_FORMAT': 'csv',
}
defaults.update(settings or {})
@@ -238,7 +240,7 @@ class FeedExportTest(unittest.TestCase):
spider_cls.start_urls = [s.url('/')]
yield runner.crawl(spider_cls)
- with open(res_name, 'rb') as f:
+ with open(res_path, 'rb') as f:
defer.returnValue(f.read())
finally: