Usage:
python setup.py test
or:
python -m mypackage.tests
from setuptools import setup | |
from setuptools.command.test import test | |
class Test(test): | |
"""Custom command called when running ``python setup.py test`` | |
""" | |
def run_tests(self): | |
from mypackage import tests | |
tests.run_tests() | |
setup( | |
name='mypackage', | |
extras_require=dict(test=['zope.testrunner']), | |
tests_require=['zope.testrunner'], | |
cmdclass=dict(test=Test) | |
) |
import sys | |
import unittest | |
class MyTestLayer(object): | |
def __init__(self): | |
self.__name__ = self.__class__.__name__ | |
self.__bases__ = [] | |
def setUp(self): | |
"""Set up test layer | |
""" | |
def tearDown(self): | |
"""Tear down test layer | |
""" | |
class MyTestCase(unittest.TestCase): | |
layer = MyTestLayer() | |
def test_foo(self): | |
"""Test something. | |
""" | |
def run_tests(): | |
from mypackage import tests | |
from zope.testrunner.runner import Runner | |
suite = unittest.TestSuite() | |
suite.addTest(unittest.findTestCases(tests)) | |
runner = Runner(found_suites=[suite]) | |
runner.run() | |
sys.exit(int(runner.failed)) | |
if __name__ == '__main__': | |
run_tests() |