From 770d69b6d1591fb414b9049437fbc423d71e82e1 Mon Sep 17 00:00:00 2001 From: justanr Date: Wed, 5 Aug 2015 10:17:41 -0400 Subject: [PATCH] Add support for running tests from setup.py Now possible to run tests with python setup.py test. Additional arguments can be passed to py.test with the '--pytest-args="opts"' flag. This commit also separates test requirements from install requirements. --- .travis.yml | 2 +- AUTHORS | 1 + requirements.txt | 4 ---- setup.py | 35 ++++++++++++++++++++++++++++++----- test_requirements.txt | 5 +++++ 5 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 test_requirements.txt diff --git a/.travis.yml b/.travis.yml index fa8d59d..7a17d16 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ python: - "3.3" # command to install dependencies install: - - "pip install -r requirements.txt" + - "pip install -r test_requirements.txt" - "pip install coveralls" # command to run tests script: diff --git a/AUTHORS b/AUTHORS index 763931c..3333b4d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,4 +10,5 @@ contributors: # Contributors * CasperVg +* Alec Reiter * Feel free to join! :) diff --git a/requirements.txt b/requirements.txt index 7fe1766..d2abb0f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,11 +20,7 @@ Jinja2==2.7.3 Mako==1.0.1 MarkupSafe==0.23 mistune==0.6 -py==1.4.29 Pygments==2.0.2 -pytest==2.7.2 -pytest-cov==1.8.1 -pytest-random==0.2 pytz==2015.4 redis==2.10.3 requests==2.7.0 diff --git a/setup.py b/setup.py index b6c4e08..c11c0f0 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,27 @@ Resources """ from setuptools import setup +from setuptools.command.test import test as TestCommand +import sys + + +class PyTestCommand(TestCommand): + user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')] + + def initialize_options(self): + super(PyTestCommand, self).initialize_options() + self.pytest_args = [] + + def finalize_options(self): + super(PyTestCommand, self).finalize_options() + self.test_args = [] + self.test_suite = True + + def run_tests(self): + import pytest + errno = pytest.main(self.pytest_args) + sys.exit(errno) + setup( name='FlaskBB', @@ -69,10 +90,6 @@ setup( 'coverage', 'itsdangerous', 'mistune', - 'py', - 'pytest', - 'pytest-cov', - 'pytest-random', 'pytz', 'redis', 'requests', @@ -80,6 +97,13 @@ setup( 'speaklater', 'sqlalchemy-utils' ], + test_suite='tests', + tests_require=[ + 'py', + 'pytest', + 'pytest-cov', + 'pytest-random' + ], dependency_links=[ 'https://github.com/jshipley/Flask-WhooshAlchemy/archive/master.zip#egg=Flask-WhooshAlchemy', 'https://github.com/sh4nks/flask-babelex/tarball/master#egg=Flask-BabelEx' @@ -94,5 +118,6 @@ setup( 'Programming Language :: Python :: 3', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 'Topic :: Software Development :: Libraries :: Python Modules' - ] + ], + cmdclass={'test': PyTestCommand} ) diff --git a/test_requirements.txt b/test_requirements.txt new file mode 100644 index 0000000..282ed6a --- /dev/null +++ b/test_requirements.txt @@ -0,0 +1,5 @@ +-r requirements.txt +py==1.4.29 +pytest==2.7.2 +pytest-cov==1.8.1 +pytest-random==0.2