Skip to content

Commit

Permalink
tests: fix py.test integration with setuptools
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Kuncar <jiri.kuncar@cern.ch>
  • Loading branch information
jirikuncar committed Aug 27, 2014
1 parent 6a4f4f2 commit 244a38e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ python:

install:
- pip install --upgrade pip --use-mirrors
- pip install coveralls pytest pytest-cov pytest-pep8 pep257 --use-mirrors
- pip install coveralls pep257 --use-mirrors
- pip install -e .[docs]

script:
- sh run_tests.sh
- pep257 dictdiffer.py
- "sphinx-build -qnNW docs docs/_build/html"
- python setup.py test

after_success:
- coveralls
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ operating correctly.

.. code-block:: console
$ py.test -q --clearcache --pep8 --doctest-modules --cov=dictdiffer.py dictdiffer.py tests.py
$ ./run_tests.sh
...
Name Stmts Miss Cover
--------------------------------
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --clearcache --pep8 --doctest-modules --cov=dictdiffer.py tests.py dictdiffer.py
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
pep257 dictdiffer.py
sphinx-build -qnNW docs docs/_build/html
py.test --clearcache --pep8 --doctest-modules --cov=dictdiffer.py dictdiffer.py tests.py
python setup.py test
38 changes: 37 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand


class PyTest(TestCommand):

user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]

def initialize_options(self):
TestCommand.initialize_options(self)
try:
from ConfigParser import ConfigParser
except ImportError:
from configparser import ConfigParser
config = ConfigParser()
config.read("pytest.ini")
self.pytest_args = config.get("pytest", "addopts").split(" ")

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True

def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)


tests_require = [
'pytest', 'pytest-cache', 'pytest-cov', 'pytest-pep8', 'coverage'
]

setup(
name='dictdiffer',
Expand All @@ -10,6 +43,9 @@
url='https://github.com/inveniosoftware/dictdiffer',
py_modules=['dictdiffer'],
extras_require={
"docs": ["sphinx_rtd_theme"],
"docs": ["sphinx_rtd_theme"] + tests_require,
},
install_requires=tests_require,
tests_require=tests_require,
cmdclass={'test': PyTest},
)
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
envlist = py26, py27, py33, py34

[testenv]
commands = {envpython} tests.py
deps = pytest
pytest-cov
pytest-pep8
commands = {envpython} setup.py test

0 comments on commit 244a38e

Please sign in to comment.