From b6445846b2d69885eac1127b00c153172e21e879 Mon Sep 17 00:00:00 2001 From: boyska Date: Mon, 23 Feb 2015 12:40:29 +0100 Subject: [PATCH 1/2] setup.py test is configurable and with coverage the previous collector was difficult to configure, while now everything can be done just editing the standard setup.cfg --- nose.cfg => setup.cfg | 2 +- setup.py | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) rename nose.cfg => setup.cfg (56%) diff --git a/nose.cfg b/setup.cfg similarity index 56% rename from nose.cfg rename to setup.cfg index e04ee12..9674587 100644 --- a/nose.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ [nosetests] all-modules=1 with-coverage=1 -cover-package=libreantdb +cover-package=libreantdb,webant diff --git a/setup.py b/setup.py index 7e5a20d..67c82b5 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ import os import sys import msgfmt -from pprint import pprint from setuptools import setup from setuptools.command.install_lib import install_lib as _install_lib from setuptools.command.develop import develop as _develop from distutils.command.build import build as _build +from setuptools.command.test import test as TestCommand from distutils.cmd import Command @@ -68,6 +68,18 @@ def run(self): _develop.run(self) +class NoseTestCommand(TestCommand): + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + # Run nose ensuring that argv simulates running nosetests directly + import nose + nose.run_exit(argv=['nosetests']) + + def read(fname): with open(os.path.join(os.path.dirname(__file__), fname)) as buf: return buf.read() @@ -97,10 +109,10 @@ def read(fname): 'webant': ['translations/*/*/*.mo'] }, include_package_data=True, - tests_require=['nose'], - test_suite='nose.collector', + tests_require=['nose', 'coverage'], zip_safe=False, cmdclass={'build': build, + 'test': NoseTestCommand, 'install_lib': install_lib, 'develop':develop, 'compile_translations': compile_translations }, From f828e54ba1cf9d72db8c32adbf8ee47db9c4125b Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 24 Feb 2015 18:45:16 +0100 Subject: [PATCH 2/2] Doc about python setup.py test --- doc/source/developer.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/developer.rst b/doc/source/developer.rst index 83e47d0..a4997d0 100644 --- a/doc/source/developer.rst +++ b/doc/source/developer.rst @@ -146,6 +146,9 @@ Unit tests are very important: if your function is testable, you should test it. Yes, even if its behaviour might seem obvious. Unit tests are important both as a way of avoding regressions and as a way to document how something behaves. +If the code you are writing is not easy to test, you should think of making it +more easy to test. Running unit tests is easy: ``python setup.py test`` is +enough. This command will run all the tests, and print a coverage summary. Ensure that the module you are writing has high coverage, and investigate what has not been covered. Contributing ------------