From 1505e29248d82311c99b8f4924293420c4b21ec2 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Fri, 26 Oct 2012 14:06:29 -0700 Subject: [PATCH] integrate pytest with setup.py --- Makefile | 6 +++--- setup.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 99b60a6d..43908092 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ build: virtualenv --no-site-packages . bin/python setup.py develop - bin/pip install -r requirements_dev.txt + bin/pip install -r requirements_dev.txt test: - ./bin/py.test tests/ + bin/python setup.py test coverage: - ./bin/py.test --cov gunicorn tests/ + bin/python setup.py test --cov clean: @rm -rf .Python bin lib include man build html diff --git a/setup.py b/setup.py index 37feeb61..2b379e2d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ import os -from setuptools import setup, find_packages +from setuptools import setup, find_packages, Command import sys from gunicorn import __version__ @@ -34,6 +34,31 @@ CLASSIFIERS = [ with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as f: long_description = f.read() +# read dev requirements +fname = os.path.join(os.path.dirname(__file__), 'requirements_dev.txt') +with open(fname) as f: + tests_require = list(map(lambda l: l.strip(), f.readlines())) + +class PyTest(Command): + user_options = [ + ("cov", None, "measure coverage") + ] + + def initialize_options(self): + self.cov = None + + def finalize_options(self): + pass + + def run(self): + import sys,subprocess + basecmd = [sys.executable, '-m', 'py.test'] + if self.cov: + basecmd += ['--cov', 'gunicorn'] + errno = subprocess.call(basecmd + ['tests']) + raise SystemExit(errno) + + setup( name = 'gunicorn', version = __version__, @@ -50,6 +75,9 @@ setup( packages = find_packages(exclude=['examples', 'tests']), include_package_data = True, + tests_require = tests_require, + cmdclass = {'test': PyTest}, + entry_points=""" [console_scripts]