Merge pull request #679 from Curita/pytest

Run tests with pytest instead of trial
This commit is contained in:
Daniel Graña 2014-04-08 10:41:03 -07:00
commit 96ef4c603c
8 changed files with 69 additions and 10 deletions

View File

@ -5,9 +5,11 @@ env:
- TOXENV=precise
- TOXENV=trunk
- TOXENV=pypy
- TOXENV=py33
matrix:
allow_failures:
- env: TOXENV=pypy
- env: TOXENV=py33
install:
- ./.travis-workarounds.sh
- pip install tox

5
pytest.ini Normal file
View File

@ -0,0 +1,5 @@
[pytest]
usefixtures = chdir setlog
python_files=test_*.py __init__.py
addopts = --doctest-modules

45
scrapy/conftest.py Normal file
View File

@ -0,0 +1,45 @@
import pytest
from twisted.python import log
from scrapy import optional_features
collect_ignore = ["stats.py"]
if 'django' not in optional_features:
collect_ignore.append("tests/test_djangoitem/models.py")
class LogObservers:
"""Class for keeping track of log observers across test modules"""
def __init__(self):
self.observers = []
def add(self, logfile='test.log'):
fileobj = open(logfile, 'wb')
observer = log.FileLogObserver(fileobj)
log.startLoggingWithObserver(observer.emit, 0)
self.observers.append((fileobj, observer))
def remove(self):
fileobj, observer = self.observers.pop()
log.removeObserver(observer.emit)
fileobj.close()
@pytest.fixture(scope='module')
def log_observers():
return LogObservers()
@pytest.fixture()
def setlog(request, log_observers):
"""Attach test.log file observer to twisted log, for trial compatibility"""
log_observers.add()
request.addfinalizer(log_observers.remove)
@pytest.fixture()
def chdir(tmpdir):
"""Change to pytest-provided temporary directory"""
tmpdir.chdir()

View File

@ -290,10 +290,11 @@ def parse_cachecontrol(header):
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
>>> parse_cachecontrol('public, max-age=3600')
{'public': None, 'max-age': '3600'}
>>> parse_cachecontrol('')
{}
>>> parse_cachecontrol('public, max-age=3600') == {'public': None,
... 'max-age': '3600'}
True
>>> parse_cachecontrol('') == {}
True
"""
directives = {}

View File

@ -27,6 +27,7 @@ class SpiderManagerTest(unittest.TestCase):
def tearDown(self):
del self.spiderman
del sys.modules['test_spiders_xxx']
sys.path.remove(self.tmpdir)
def test_interface(self):

View File

@ -7,12 +7,12 @@ from scrapy.contrib.loader import ItemLoader
class TestItem(Item):
name = Field()
def test_processor(x):
def _test_procesor(x):
return x + x
class TestLoader(ItemLoader):
default_item_class = TestItem
name_out = staticmethod(test_processor)
name_out = staticmethod(_test_procesor)
class MarshalFifoDiskQueueTest(t.FifoDiskQueueTest):

View File

@ -1,3 +1,4 @@
# Tests requirements
mock
mitmproxy >= 0.10
pytest-twisted

12
tox.ini
View File

@ -5,6 +5,8 @@
[tox]
envlist = py27, pypy, precise, trunk, py33
indexserver =
HPK = https://devpi.net/hpk/dev/
[testenv]
deps =
@ -15,7 +17,7 @@ deps =
django
-rtests-requirements.txt
commands =
trial {posargs:scrapy}
py.test --twisted {posargs:scrapy}
[testenv:precise]
basepython = python2.7
@ -34,7 +36,7 @@ basepython = python2.7
commands =
pip install https://github.com/scrapy/w3lib/archive/master.zip#egg=w3lib
pip install https://github.com/scrapy/queuelib/archive/master.zip#egg=queuelib
trial {posargs:scrapy}
py.test --twisted {posargs:scrapy}
[testenv:py33]
basepython = python3.3
@ -45,8 +47,10 @@ deps =
cssselect>=0.9
queuelib>=1.1.1
w3lib>=1.5
commands =
trial {posargs:scrapy}
# tests requirements
mock
:HPK:pytest>2.5.2
pytest-twisted
[testenv:windows]
commands =