Browse Source

Merge pull request #136 from justanr/test_command

Add support for running tests from setup.py
Peter Justin 9 years ago
parent
commit
cdee77ba80
5 changed files with 37 additions and 10 deletions
  1. 1 1
      .travis.yml
  2. 1 0
      AUTHORS
  3. 0 4
      requirements.txt
  4. 30 5
      setup.py
  5. 5 0
      test_requirements.txt

+ 1 - 1
.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:

+ 1 - 0
AUTHORS

@@ -10,4 +10,5 @@ contributors:
 # Contributors
 
 * CasperVg
+* Alec Reiter <https://github.com/justanr>
 * Feel free to join! :)

+ 0 - 4
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

+ 30 - 5
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}
 )

+ 5 - 0
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