~launchpad-pqm/launchpad/devel

3944.1.1 by Francis J. Lacoste
Use system version python2.4 for scripts.
1
#!/usr/bin/python2.4
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
2
##############################################################################
3
#
4
# Copyright (c) 2004 Zope Corporation and Contributors.
5
# All Rights Reserved.
6
#
7
# This software is subject to the provisions of the Zope Public License,
8
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
9
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
10
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
11
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
12
# FOR A PARTICULAR PURPOSE.
13
#
14
##############################################################################
15
"""Test script
16
17
$Id: test.py 25177 2004-06-02 13:17:31Z jim $
18
"""
2976.10.61 by Stuart Bishop
Update warning filters
19
import sys, os, psycopg, time, logging, warnings, re
809 by Canonical.com Patch Queue Manager
Nuke some arch-tags
20
2083 by Canonical.com Patch Queue Manager
[r=jamesh] testrunner improvements (?)
21
os.setpgrp() # So test_on_merge.py can reap its children
22
23
# Make tests run in a timezone no launchpad developers live in.
24
# Our tests need to run in any timezone.
25
# (No longer actually required, as PQM does this)
26
os.environ['TZ'] = 'Asia/Calcutta'
27
time.tzset()
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
28
29
here = os.path.dirname(os.path.realpath(__file__))
1806 by Canonical.com Patch Queue Manager
Always use sys.path.insert instead of sys.path.append to give precedence for launchpad libs that are inside our tree. r=stub
30
sys.path.insert(0, os.path.join(here, 'lib'))
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
31
32
# Set PYTHONPATH environment variable for spawned processes
33
os.environ['PYTHONPATH'] = ':'.join(sys.path)
34
4385.1.2 by Stuart Bishop
Add profiling information on test suite infrastructure
35
# Set a flag if this is the main testrunner process
36
if len(sys.argv) > 1 and sys.argv[1] == '--resume-layer':
37
    main_process = False
38
else:
39
    main_process = True
40
2097 by Canonical.com Patch Queue Manager
[trivial] more import fascist improvements
41
# Install the import fascist import hook and atexit handler.
42
import importfascist
43
importfascist.install_import_fascist()
1968 by Canonical.com Patch Queue Manager
DatabaseCodeImportFascist: warn about database imports in browser code after running tests. [r=SteveA]
44
2103 by Canonical.com Patch Queue Manager
[trivial] improved warning output for tests, and fixed a bunch of ambiguous use of select results warnings. some xxx comments left in person code. one untested codepath in hct backend.
45
# Install the warning handler hook and atexit handler.
46
import warninghandler
47
warninghandler.install_warning_handler()
48
2976.10.126 by Stuart Bishop
Ensure ZCML overrides are generated
49
# Ensure overrides are generated
50
from configs import generate_overrides
51
generate_overrides()
2103 by Canonical.com Patch Queue Manager
[trivial] improved warning output for tests, and fixed a bunch of ambiguous use of select results warnings. some xxx comments left in person code. one untested codepath in hct backend.
52
2083 by Canonical.com Patch Queue Manager
[r=jamesh] testrunner improvements (?)
53
# Tell canonical.config to use the test config section in launchpad.conf
1628 by Canonical.com Patch Queue Manager
Configuration, Librian and Librarian test harness work
54
from canonical.config import config
55
config.setDefaultSection('testrunner')
56
3498.5.2 by Bjorn Tillenius
clarify a comment.
57
# Remove this module's directory from path, so that zope.testbrowser
58
# can import pystone from test:
3498.4.1 by Bjorn Tillenius
patch test.py to remove '.' from the python path, to allow testbrowser import pystone from test.
59
sys.path[:] = [p for p in sys.path if os.path.abspath(p) != here]
60
61
1210 by Canonical.com Patch Queue Manager
Refactor and document test harnesses
62
# Turn on psycopg debugging wrapper
63
#import canonical.database.debug
64
#canonical.database.debug.install()
65
2770.1.30 by Guilherme Salgado
Clean up the http_proxy env var before running tests, as we don't want the requests we make to localhost to be proxied
66
# Unset the http_proxy environment variable, because we're going to make
67
# requests to localhost and we don't wand this to be proxied.
68
try:
69
    os.environ.pop('http_proxy')
70
except KeyError:
71
    pass
72
2976.10.30 by Stuart Bishop
filter some test suite warnings
73
# Silence spurious warnings. Note that this does not propagate to subprocesses
74
# so this is not always as easy as it seems. Warnings caused by our code that
75
# need to be silenced should have an accomponied Bug reference.
2976.10.19 by Stuart Bishop
Update test.py for Zope3.2
76
#
77
warnings.filterwarnings(
78
        'ignore', 'PyCrypto', RuntimeWarning, 'twisted[.]conch[.]ssh'
79
        )
80
warnings.filterwarnings(
2976.10.30 by Stuart Bishop
filter some test suite warnings
81
        'ignore', 'twisted.python.plugin', DeprecationWarning, 'buildbot'
82
        )
83
warnings.filterwarnings(
84
        'ignore', 'The concrete concept of a view has been deprecated.',
85
        DeprecationWarning
86
        )
2976.10.116 by Stuart Bishop
Fix and update tests
87
warnings.filterwarnings(
88
        'ignore', 'bzrlib.*was deprecated', DeprecationWarning
89
        )
2976.10.30 by Stuart Bishop
filter some test suite warnings
90
2976.10.61 by Stuart Bishop
Update warning filters
91
# This warning will be triggered if the beforeTraversal hook fails. We
92
# want to ensure it is not raised as an error, as this will mask the real
93
# problem.
94
warnings.filterwarnings(
95
        'always',
96
        re.escape('clear_request_started() called outside of a request'),
97
        UserWarning
98
        )
99
2976.10.30 by Stuart Bishop
filter some test suite warnings
100
# Any warnings not explicitly silenced are errors
101
warnings.filterwarnings('error', append=True)
102
1210 by Canonical.com Patch Queue Manager
Refactor and document test harnesses
103
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
104
from canonical.ftests import pgsql
1617 by Canonical.com Patch Queue Manager
Refactor PostgreSQL harnesses to avoid bug found by ddaa. Add more tests
105
# If this is removed, make sure canonical.ftests.pgsql is updated
106
# because the test harness there relies on the Connection wrapper being
107
# installed.
1224 by Canonical.com Patch Queue Manager
Test isolation enforcement
108
pgsql.installFakeConnect()
109
2976.10.19 by Stuart Bishop
Update test.py for Zope3.2
110
from zope.testing import testrunner
111
112
defaults = [
113
    # Find tests in the tests and ftests directories
114
    '--tests-pattern=^f?tests$',
115
    '--test-path=%s' % os.path.join(here, 'lib'),
116
    '--package=canonical',
117
    ]
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
118
119
if __name__ == '__main__':
4385.1.5 by Stuart Bishop
Docstrings and comments
120
4385.1.10 by Stuart Bishop
Review updates
121
    # Extract arguments so we can see them too. We need to strip --resume-layer
122
    # and --default stuff if found as get_options can't handle it.
123
    if len(sys.argv) > 1 and sys.argv[1] == '--resume-layer':
124
        args = list(sys.argv)
125
        args.pop(1) # --resume-layer
126
        args.pop(1) # The layer name
127
        while len(args) > 1 and args[1] == '--default':
128
            args.pop(1) # --default
129
            args.pop(1) # The default value
130
        args.insert(0, sys.argv[0])
131
    else:
132
        args = sys.argv
133
    options = testrunner.get_options(args=args, defaults=defaults)
4385.1.5 by Stuart Bishop
Docstrings and comments
134
4385.1.7 by Stuart Bishop
Don't want profiling overhead if profiling not requested
135
    # Turn on Layer profiling if requested.
136
    from canonical.testing import profiled
4385.1.10 by Stuart Bishop
Review updates
137
    if options.verbose >= 3 and main_process:
4385.1.11 by Stuart Bishop
Review feedback
138
        profiled.setup_profiling()
4385.1.7 by Stuart Bishop
Don't want profiling overhead if profiling not requested
139
5642.2.1 by Elliot Murphy
Set the working directory for the test runner script.
140
    # The working directory change is just so that the test script
141
    # can be invoked from places other than the root of the source
142
    # tree. This is very useful for IDE integration, so an IDE can
143
    # e.g. run the test that you are currently editing.
144
    try:
145
        there = os.getcwd()
146
        os.chdir(here)
147
        result = testrunner.run(defaults)
148
    finally:
149
        os.chdir(there)
2976.10.19 by Stuart Bishop
Update test.py for Zope3.2
150
    # Cribbed from sourcecode/zope/test.py - avoid spurious error during exit.
151
    logging.disable(999999999)
4385.1.2 by Stuart Bishop
Add profiling information on test suite infrastructure
152
4385.1.7 by Stuart Bishop
Don't want profiling overhead if profiling not requested
153
    # Print Layer profiling report if requested.
4385.1.5 by Stuart Bishop
Docstrings and comments
154
    if main_process and options.verbose >= 3:
4385.1.7 by Stuart Bishop
Don't want profiling overhead if profiling not requested
155
        profiled.report_profile_stats()
2976.10.19 by Stuart Bishop
Update test.py for Zope3.2
156
    sys.exit(result)
157