Skip to content

Commit

Permalink
Merge pull request #103 from boyska/nose-coverage
Browse files Browse the repository at this point in the history
setup.py test is configurable and with coverage
  • Loading branch information
ael-code committed Feb 24, 2015
2 parents d75b50b + f828e54 commit dc044ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/source/developer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down
2 changes: 1 addition & 1 deletion nose.cfg → setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[nosetests]
all-modules=1
with-coverage=1
cover-package=libreantdb
cover-package=libreantdb,webant
18 changes: 15 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit dc044ad

Please sign in to comment.