~landscape/zope3/newer-from-ztk

« back to all changes in this revision

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

  • Committer: Thomas Hervé
  • Date: 2009-09-21 16:46:07 UTC
  • Revision ID: thomas@canonical.com-20090921164607-sky3xhlt02ji80ka
Revert r8: regression with test failures

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Knitting in extra package directories
 
2
=====================================
 
3
 
 
4
Python packages have __path__ variables that can be manipulated to add
 
5
extra directories cntaining software used in the packages.  The
 
6
testrunner needs to be given extra information about this sort of
 
7
situation.
 
8
 
 
9
Let's look at an example.  The testrunner-ex-knit-lib directory
 
10
is a directory that we want to add to the Python path, but that we
 
11
don't want to search for tests.  It has a sample4 package and a
 
12
products subpackage.  The products subpackage adds the
 
13
testrunner-ex-knit-products to it's __path__.  We want to run tests
 
14
from the testrunner-ex-knit-products directory.  When we import these
 
15
tests, we need to import them from the sample4.products package.  We
 
16
can't use the --path option to name testrunner-ex-knit-products.
 
17
It isn't enough to add the containing directory to the test path
 
18
because then we wouldn't be able to determine the package name
 
19
properly.  We might be able to use the --package option to run the
 
20
tests from the sample4/products package, but we want to run tests in
 
21
testrunner-ex that aren't in this package.  
 
22
 
 
23
We can use the --package-path option in this case.  The --package-path
 
24
option is like the --test-path option in that it defines a path to be
 
25
searched for tests without affecting the python path.  It differs in
 
26
that it supplied a package name that is added a profex when importing
 
27
any modules found.  The --package-path option takes *two* arguments, a
 
28
package name and file path.
 
29
 
 
30
    >>> import os.path, sys
 
31
    >>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
 
32
    >>> sys.path.append(os.path.join(this_directory, 'testrunner-ex-pp-lib'))
 
33
    >>> defaults = [
 
34
    ...     '--path', directory_with_tests,
 
35
    ...     '--tests-pattern', '^sampletestsf?$',
 
36
    ...     '--package-path',
 
37
    ...     os.path.join(this_directory, 'testrunner-ex-pp-products'),
 
38
    ...     'sample4.products',
 
39
    ...     ]
 
40
 
 
41
    >>> from zope.testing import testrunner
 
42
    
 
43
    >>> sys.argv = 'test --layer Layer111 -vv'.split()
 
44
    >>> _ = testrunner.run(defaults)
 
45
    Running tests at level 1
 
46
    Running samplelayers.Layer111 tests:
 
47
      Set up samplelayers.Layerx in 0.000 seconds.
 
48
      Set up samplelayers.Layer1 in 0.000 seconds.
 
49
      Set up samplelayers.Layer11 in 0.000 seconds.
 
50
      Set up samplelayers.Layer111 in 0.000 seconds.
 
51
      Running:
 
52
        test_x1 (sample1.sampletests.test111.TestA)
 
53
        test_y0 (sample1.sampletests.test111.TestA)
 
54
        ...
 
55
        test_y0 (sampletests.test111)
 
56
        test_z1 (sampletests.test111)
 
57
        testrunner-ex/sampletests/../sampletestsl.txt
 
58
        test_extra_test_in_products (sample4.products.sampletests.Test)
 
59
        test_another_test_in_products (sample4.products.more.sampletests.Test)
 
60
      Ran 36 tests with 0 failures and 0 errors in 0.008 seconds.
 
61
    Tearing down left over layers:
 
62
      Tear down samplelayers.Layer111 in 0.000 seconds.
 
63
      Tear down samplelayers.Layerx in 0.000 seconds.
 
64
      Tear down samplelayers.Layer11 in 0.000 seconds.
 
65
      Tear down samplelayers.Layer1 in 0.000 seconds.
 
66
 
 
67
In the example, the last test, test_extra_test_in_products, came from
 
68
the products directory.  As usual, we can select the knit-in packages
 
69
or individual packages within knit-in packages:
 
70
 
 
71
    >>> sys.argv = 'test --package sample4.products -vv'.split()
 
72
    >>> _ = testrunner.run(defaults)
 
73
    Running tests at level 1
 
74
    Running samplelayers.Layer111 tests:
 
75
      Set up samplelayers.Layerx in 0.000 seconds.
 
76
      Set up samplelayers.Layer1 in 0.000 seconds.
 
77
      Set up samplelayers.Layer11 in 0.000 seconds.
 
78
      Set up samplelayers.Layer111 in 0.000 seconds.
 
79
      Running:
 
80
        test_extra_test_in_products (sample4.products.sampletests.Test)
 
81
        test_another_test_in_products (sample4.products.more.sampletests.Test)
 
82
      Ran 2 tests with 0 failures and 0 errors in 0.000 seconds.
 
83
    Tearing down left over layers:
 
84
      Tear down samplelayers.Layer111 in 0.000 seconds.
 
85
      Tear down samplelayers.Layerx in 0.000 seconds.
 
86
      Tear down samplelayers.Layer11 in 0.000 seconds.
 
87
      Tear down samplelayers.Layer1 in 0.000 seconds.
 
88
 
 
89
    >>> sys.argv = 'test --package sample4.products.more -vv'.split()
 
90
    >>> _ = testrunner.run(defaults)
 
91
    Running tests at level 1
 
92
    Running samplelayers.Layer111 tests:
 
93
      Set up samplelayers.Layerx in 0.000 seconds.
 
94
      Set up samplelayers.Layer1 in 0.000 seconds.
 
95
      Set up samplelayers.Layer11 in 0.000 seconds.
 
96
      Set up samplelayers.Layer111 in 0.000 seconds.
 
97
      Running:
 
98
        test_another_test_in_products (sample4.products.more.sampletests.Test)
 
99
      Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
 
100
    Tearing down left over layers:
 
101
      Tear down samplelayers.Layer111 in 0.000 seconds.
 
102
      Tear down samplelayers.Layerx in 0.000 seconds.
 
103
      Tear down samplelayers.Layer11 in 0.000 seconds.
 
104
      Tear down samplelayers.Layer1 in 0.000 seconds.
 
105