~gary/zope.testing/3.9.4-p4

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner/testrunner-discovery.txt

  • Committer: Maris Fogels
  • Date: 2010-06-04 14:58:44 UTC
  • Revision ID: maris.fogels@canonical.com-20100604145844-mb48c1ig9gty2kao
Initial import of zope.testing's 3.9.4 SVN tag

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Automatically discovering tests
 
2
===============================
 
3
 
 
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:
 
9
 
 
10
    >>> import os, sys
 
11
    >>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
 
12
 
 
13
    >>> from zope.testing import testrunner
 
14
 
 
15
    >>> defaults = [
 
16
    ...     '--path', directory_with_tests,
 
17
    ...     '--tests-pattern', '^sampletestsf?$',
 
18
    ...     ]
 
19
    >>> sys.argv = ['test',
 
20
    ...             '--tests-pattern', '^sampletests_discover$',
 
21
    ...     ]
 
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.
 
28
    False
 
29
 
 
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:
 
32
 
 
33
    >>> sys.argv = ['test',
 
34
    ...             '--tests-pattern', '^sampletests_discover_notests$',
 
35
    ...     ]
 
36
    >>> testrunner.run(defaults)
 
37
    Test-module import failures:
 
38
    <BLANKLINE>
 
39
    Module: sample1.sampletests_discover_notests
 
40
    <BLANKLINE>
 
41
    TypeError: Module sample1.sampletests_discover_notests does not define any tests
 
42
    <BLANKLINE>
 
43
    <BLANKLINE>
 
44
    <BLANKLINE>
 
45
    Test-modules with import problems:
 
46
      sample1.sampletests_discover_notests
 
47
    Total: 0 tests, 0 failures, 0 errors in 0.000 seconds.
 
48
    True