1
Automatically discovering tests
2
===============================
4
You can explicitly specify which tests to run by providing a function that
5
returns a unittest.TestSuite in the test modules (the name of the function can
6
be configured with the --suite-name parameter, it defaults to 'test_suite'). If
7
no such function is present, testrunner will use all classes in the module that
8
inherit from unittest.TestCase as tests:
11
>>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
13
>>> from zope.testing import testrunner
16
... '--path', directory_with_tests,
17
... '--tests-pattern', '^sampletestsf?$',
19
>>> sys.argv = ['test',
20
... '--tests-pattern', '^sampletests_discover$',
22
>>> testrunner.run(defaults)
23
Running zope.testing.testrunner.layer.UnitTests tests:
24
Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
25
Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
26
Tearing down left over layers:
27
Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
30
If the module neither provides a TestSuite nor has discoverable tests,
31
testrunner will exit with an error to prevent acidentally missing test cases:
33
>>> sys.argv = ['test',
34
... '--tests-pattern', '^sampletests_discover_notests$',
36
>>> testrunner.run(defaults)
37
Test-module import failures:
39
Module: sample1.sampletests_discover_notests
41
TypeError: Module sample1.sampletests_discover_notests does not define any tests
45
Test-modules with import problems:
46
sample1.sampletests_discover_notests
47
Total: 0 tests, 0 failures, 0 errors in 0.000 seconds.