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 # Find right directory when running from source tree
32 sys
.path
.insert(0, "bin/python")
36 samba
.ensure_external_module("testtools", "testtools")
37 samba
.ensure_external_module("subunit", "subunit/python")
38 from subunit
.run
import SubunitTestRunner
39 import samba
.getopt
as options
43 usage
= 'subunitrun [options] <tests>'
45 This runs a Samba python test suite. The tests are typically located in
46 source4/scripting/python/samba/tests/*.py
48 To run the tests from one of those modules, specify the test as
49 samba.tests.MODULE. For example, to run the tests in common.py:
51 subunitrun samba.tests.common
53 To list the tests in that module, use:
55 subunitrun -l samba.tests.common
57 NOTE: This script is deprecated in favor of "python -m subunit.run". Don't use
58 it unless it can be avoided.
61 def format_description(formatter
):
62 '''hack to prevent textwrap of the description'''
65 parser
= optparse
.OptionParser(usage
=usage
, description
=description
)
66 parser
.format_description
= format_description
67 credopts
= options
.CredentialsOptions(parser
)
68 sambaopts
= options
.SambaOptions(parser
)
69 parser
.add_option_group(credopts
)
70 parser
.add_option_group(sambaopts
)
72 from subunit
.run
import TestProgram
74 from unittest
import TestProgram
76 parser
.add_option('-l', '--list', dest
='listtests', default
=False,
77 help='List tests rather than running them.',
80 opts
, args
= parser
.parse_args()
82 if getattr(opts
, "listtests", False):
83 args
.insert(0, "--list")
85 lp
= sambaopts
.get_loadparm()
86 samba
.tests
.cmdline_credentials
= credopts
.get_credentials(lp
)
88 runner
= SubunitTestRunner()
89 program
= TestProgram(module
=None, argv
=[sys
.argv
[0]] + args
, testRunner
=runner
)