Skip to content

Instantly share code, notes, and snippets.

@rnixx
Last active March 25, 2019 13:42
Show Gist options
  • Save rnixx/780b20d1914ee81c4fcbd9aa1ce14520 to your computer and use it in GitHub Desktop.
Save rnixx/780b20d1914ee81c4fcbd9aa1ce14520 to your computer and use it in GitHub Desktop.
Lightweight zope.testrunner integration on package level for layered tests

Lightweight zope.testrunner integration on package level for layered tests

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment