From 108c3e63a5ec1b251134dc4742f87d9933e9c619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Wed, 12 Aug 2015 16:40:04 -0300 Subject: [PATCH 1/5] Add coverage report trough codecov.io --- .coveragerc | 18 +++++++++++++++++- .travis.yml | 5 ++++- README.rst | 4 ++++ tests/requirements-py3.txt | 1 + tests/requirements.txt | 1 + tox.ini | 4 ++-- 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.coveragerc b/.coveragerc index 3baaf659a..3105409ba 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,3 +1,19 @@ [run] +branch = true include = scrapy/* -omit = scrapy/xlib*,scrapy/tests* +omit = + tests/* + scrapy/xlib/* + scrapy/conf.py + scrapy/stats.py + scrapy/project.py + scrapy/utils/decorator.py + scrapy/statscol.py + scrapy/squeue.py + scrapy/log.py + scrapy/dupefilter.py + scrapy/command.py + scrapy/linkextractor.py + scrapy/spider.py + scrapy/contrib/* + scrapy/contrib_exp/* diff --git a/.travis.yml b/.travis.yml index d714c0ff8..aee08919e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,11 @@ env: - TOXENV=py33 - TOXENV=docs install: - - pip install -U tox twine wheel + - pip install -U tox twine wheel codecov coveralls script: tox +after_success: + - codecov + - coveralls notifications: irc: use_notice: true diff --git a/README.rst b/README.rst index 7006925ae..ec3604875 100644 --- a/README.rst +++ b/README.rst @@ -18,6 +18,10 @@ Scrapy :target: https://github.com/scrapy/scrapy/wiki/Python-3-Porting :alt: Python 3 Porting Status +.. image:: https://img.shields.io/codecov/c/github/scrapy/scrapy/master.svg + :target: http://codecov.io/github/scrapy/scrapy?branch=master + :alt: Coverage report + Overview ======== diff --git a/tests/requirements-py3.txt b/tests/requirements-py3.txt index 8f9e22f0b..e37a2e68d 100644 --- a/tests/requirements-py3.txt +++ b/tests/requirements-py3.txt @@ -1,4 +1,5 @@ pytest>=2.6.0 pytest-twisted +pytest-cov testfixtures jmespath diff --git a/tests/requirements.txt b/tests/requirements.txt index 4f1520021..452a884e0 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -3,5 +3,6 @@ mock mitmproxy==0.10.1 netlib==0.10.1 pytest-twisted +pytest-cov jmespath testfixtures diff --git a/tox.ini b/tox.ini index 9e5b2fa13..806219898 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ deps = leveldb -rtests/requirements.txt commands = - py.test {posargs:scrapy tests} + py.test --cov=scrapy {posargs:scrapy tests} [testenv:precise] basepython = python2.7 @@ -34,7 +34,7 @@ basepython = python2.7 commands = pip install -U https://github.com/scrapy/w3lib/archive/master.zip#egg=w3lib pip install -U https://github.com/scrapy/queuelib/archive/master.zip#egg=queuelib - py.test {posargs:scrapy tests} + py.test --cov=scrapy {posargs:scrapy tests} [testenv:py33] basepython = python3.3 From cb9577a6d4e67fd361ec18d6ff49cc85001d1350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Thu, 13 Aug 2015 19:02:36 -0300 Subject: [PATCH 2/5] Do not be verbose with coverage report by default --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 806219898..8b4c9e875 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ deps = leveldb -rtests/requirements.txt commands = - py.test --cov=scrapy {posargs:scrapy tests} + py.test --cov=scrapy --cov-report= {posargs:scrapy tests} [testenv:precise] basepython = python2.7 @@ -34,7 +34,7 @@ basepython = python2.7 commands = pip install -U https://github.com/scrapy/w3lib/archive/master.zip#egg=w3lib pip install -U https://github.com/scrapy/queuelib/archive/master.zip#egg=queuelib - py.test --cov=scrapy {posargs:scrapy tests} + py.test --cov=scrapy --cov-report= {posargs:scrapy tests} [testenv:py33] basepython = python3.3 From 54f98378042455f1c21848b19d68e65dd07f0ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Thu, 13 Aug 2015 19:02:51 -0300 Subject: [PATCH 3/5] Document how to get coverage report --- docs/contributing.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/contributing.rst b/docs/contributing.rst index ad9a3805a..be34bf98c 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -154,6 +154,13 @@ To run a specific test (say ``tests/test_loader.py``) use: ``tox -- tests/test_loader.py`` +To see coverage report install `coverage`_ (``pip install coverage``) and run: + + ``coverage report`` + +see output of ``coverage --help`` for more options like html or xml report. + +.. _coverage: https://pypi.python.org/pypi/coverage Writing tests ------------- From 43fc2f23b80083f89ae1e982bfdee5d4e0322556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Thu, 13 Aug 2015 19:30:06 -0300 Subject: [PATCH 4/5] Increase coverage of version command --- tests/test_command_version.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_command_version.py b/tests/test_command_version.py index 420713d87..37e1f2543 100644 --- a/tests/test_command_version.py +++ b/tests/test_command_version.py @@ -14,4 +14,16 @@ class VersionTest(ProcessTest, unittest.TestCase): def test_output(self): encoding = getattr(sys.stdout, 'encoding') or 'utf-8' _, out, _ = yield self.execute([]) - self.assertEqual(out.strip().decode(encoding), "Scrapy %s" % scrapy.__version__) + self.assertEqual( + out.strip().decode(encoding), + "Scrapy %s" % scrapy.__version__, + ) + + @defer.inlineCallbacks + def test_verbose_output(self): + encoding = getattr(sys.stdout, 'encoding') or 'utf-8' + _, out, _ = yield self.execute(['-v']) + headers = [l.partition(":")[0].strip() + for l in out.strip().decode(encoding).splitlines()] + self.assertEqual(headers, ['Scrapy', 'lxml', 'libxml2', 'Twisted', + 'Python', 'pyOpenSSL', 'Platform']) From 27077d2b6cb398cfb54d58c061e233b929868ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Thu, 13 Aug 2015 20:52:38 -0300 Subject: [PATCH 5/5] Forward coverage envvars needed to cover subprocess --- tests/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/__init__.py b/tests/__init__.py index d017afad4..d940f28ea 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -13,6 +13,14 @@ os.environ['http_proxy'] = '' os.environ['https_proxy'] = '' os.environ['ftp_proxy'] = '' +# Absolutize paths to coverage config and output file because tests that +# spawn subprocesses also changes current working directory. +_sourceroot = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if 'COV_CORE_CONFIG' in os.environ: + os.environ['COVERAGE_FILE'] = os.path.join(_sourceroot, '.coverage') + os.environ['COV_CORE_CONFIG'] = os.path.join(_sourceroot, + os.environ['COV_CORE_CONFIG']) + try: import unittest.mock as mock except ImportError: