3 # Simple subunit testrunner for python
5 # NOTE: This is deprecated - Using the standard subunit runner is
6 # preferred - e.g. "python -m subunit.run YOURMODULE".
8 # This wrapper will be removed once all tests can be run
9 # without it. At the moment there are various tests which still
10 # get e.g. credentials passed via command-line options to this
13 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2011
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 3 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program. If not, see <http://www.gnu.org/licenses/>.
31 # make sure the script dies immediately when hitting control-C,
32 # rather than raising KeyboardInterrupt. As we do all database
33 # operations using transactions, this is safe.
35 signal
.signal(signal
.SIGINT
, signal
.SIG_DFL
)
37 # Find right directory when running from source tree
38 sys
.path
.insert(0, "bin/python")
42 samba
.ensure_external_module("testtools", "testtools")
43 samba
.ensure_external_module("subunit", "subunit/python")
44 from subunit
.run
import SubunitTestRunner
45 import samba
.getopt
as options
49 usage
= 'subunitrun [options] <tests>'
51 This runs a Samba python test suite. The tests are typically located in
52 source4/scripting/python/samba/tests/*.py
54 To run the tests from one of those modules, specify the test as
55 samba.tests.MODULE. For example, to run the tests in common.py:
57 subunitrun samba.tests.common
59 To list the tests in that module, use:
61 subunitrun -l samba.tests.common
63 NOTE: This script is deprecated in favor of "python -m subunit.run". Don't use
64 it unless it can be avoided.
67 def format_description(formatter
):
68 '''hack to prevent textwrap of the description'''
71 parser
= optparse
.OptionParser(usage
=usage
, description
=description
)
72 parser
.format_description
= format_description
73 credopts
= options
.CredentialsOptions(parser
)
74 sambaopts
= options
.SambaOptions(parser
)
75 parser
.add_option_group(credopts
)
76 parser
.add_option_group(sambaopts
)
78 from subunit
.run
import TestProgram
80 from unittest
import TestProgram
82 parser
.add_option('-l', '--list', dest
='listtests', default
=False,
83 help='List tests rather than running them.',
86 opts
, args
= parser
.parse_args()
88 if getattr(opts
, "listtests", False):
89 args
.insert(0, "--list")
91 lp
= sambaopts
.get_loadparm()
92 samba
.tests
.cmdline_credentials
= credopts
.get_credentials(lp
)
94 runner
= SubunitTestRunner()
95 program
= TestProgram(module
=None, argv
=[sys
.argv
[0]] + args
, testRunner
=runner
)