From f982efda6ad9a4b4b0973b4c811cd8f6905a1cd8 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Wed, 15 Apr 2015 12:08:54 -0400 Subject: Integrate py.test with setup.py test --- .gitignore | 1 + setup.py | 32 +++++++++++++++++++++++++++++++- tox.ini | 6 ++---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2e98181..288f2ad 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__ .tox doc/_build/ .coverage +.eggs diff --git a/setup.py b/setup.py index c376f87..c4fbbd5 100755 --- a/setup.py +++ b/setup.py @@ -8,12 +8,36 @@ Installation script for the OpenSSL module """ +import sys + from setuptools import setup +from setuptools.command.test import test as TestCommand # XXX Deduplicate this __version__ = '0.15.1' + +class PyTest(TestCommand): + user_options = [("pytest-args=", "a", "Arguments to pass to py.test")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.pytest_args = None + + 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 or [] + + ["OpenSSL"]) + sys.exit(errno) + + setup(name='pyOpenSSL', version=__version__, packages = ['OpenSSL'], package_dir = {'OpenSSL': 'OpenSSL'}, @@ -75,4 +99,10 @@ High-level wrapper around a subset of the OpenSSL library, includes 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: System :: Networking', ], - test_suite="OpenSSL") + test_suite="OpenSSL", + tests_require=[ + "pytest", + ], + cmdclass={ + "test": PyTest, + }) diff --git a/tox.ini b/tox.ini index 60a15ce..da54916 100644 --- a/tox.ini +++ b/tox.ini @@ -3,15 +3,13 @@ envlist = pypy,py26,py27,py32,py33,py34 [testenv] deps = - setuptools>=7.0 + setuptools>=7.0 # older setuptools pollute CWD with egg files of dependencies coverage - pytest setenv = # Do not allowed the executing environment to pollute the test environment # with extra packages. PYTHONPATH= -# The standard library unittest module can run tests on Python 2.7 and newer commands = python -c "import OpenSSL.SSL; print(OpenSSL.SSL.SSLeay_version(OpenSSL.SSL.SSLEAY_VERSION))" - coverage run --branch --source=OpenSSL -m pytest OpenSSL + coverage run --branch --source=OpenSSL setup.py test coverage report -m -- cgit v1.2.1