本文整理汇总了Python中unittest.TestProgram方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.TestProgram方法的具体用法?Python unittest.TestProgram怎么用?Python unittest.TestProgram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest
的用法示例。
在下文中一共展示了unittest.TestProgram方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWarning
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def testWarning(self):
"""Test the warnings argument"""
# see #10535
class FakeTP(unittest.TestProgram):
def parseArgs(self, *args, **kw): pass
def runTests(self, *args, **kw): pass
warnoptions = sys.warnoptions[:]
try:
sys.warnoptions[:] = []
# no warn options, no arg -> default
self.assertEqual(FakeTP().warnings, 'default')
# no warn options, w/ arg -> arg value
self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore')
sys.warnoptions[:] = ['somevalue']
# warn options, no arg -> None
# warn options, w/ arg -> arg value
self.assertEqual(FakeTP().warnings, None)
self.assertEqual(FakeTP(warnings='ignore').warnings, 'ignore')
finally:
sys.warnoptions[:] = warnoptions
示例2: __init__
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def __init__(self, module=None, defaultTest='.', argv=None,
testRunner=None, testLoader=None, env=None, config=None,
suite=None, exit=True, plugins=None, addplugins=None):
if env is None:
env = os.environ
if config is None:
config = self.makeConfig(env, plugins)
if addplugins:
config.plugins.addPlugins(extraplugins=addplugins)
self.config = config
self.suite = suite
self.exit = exit
extra_args = {}
version = sys.version_info[0:2]
if version >= (2,7) and version != (3,0):
extra_args['exit'] = exit
unittest.TestProgram.__init__(
self, module=module, defaultTest=defaultTest,
argv=argv, testRunner=testRunner, testLoader=testLoader,
**extra_args)
示例3: test_defaultTest_with_iterable
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def test_defaultTest_with_iterable(self):
class FakeRunner(object):
def run(self, test):
self.test = test
return True
old_argv = sys.argv
sys.argv = ['faketest']
runner = FakeRunner()
program = unittest.TestProgram(
testRunner=runner, exit=False,
defaultTest=['unittest.test', 'unittest.test2'],
testLoader=self.FooBarLoader())
sys.argv = old_argv
self.assertEqual(['unittest.test', 'unittest.test2'],
program.testNames)
示例4: main
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def main(*args, **kwargs):
# pylint: disable=g-doc-args
"""Executes a set of Python unit tests.
Usually this function is called without arguments, so the
unittest.TestProgram instance will get created with the default settings,
so it will run all test methods of all TestCase classes in the __main__
module.
Args:
args: Positional arguments passed through to unittest.TestProgram.__init__.
kwargs: Keyword arguments passed through to unittest.TestProgram.__init__.
"""
# pylint: enable=g-doc-args
_RunInApp(RunTests, args, kwargs)
示例5: run_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def run_tests(argv, args, kwargs): # pylint: disable=line-too-long
# type: (MutableSequence[Text], Sequence[Any], MutableMapping[Text, Any]) -> None
# pylint: enable=line-too-long
"""Executes a set of Python unit tests.
Most users should call absltest.main() instead of run_tests.
Please note that run_tests should be called from app.run.
Calling absltest.main() would ensure that.
Please note that run_tests is allowed to make changes to kwargs.
Args:
argv: sys.argv with the command-line flags removed from the front, i.e. the
argv with which app.run() has called __main__.main.
args: Positional arguments passed through to unittest.TestProgram.__init__.
kwargs: Keyword arguments passed through to unittest.TestProgram.__init__.
"""
result = _run_and_get_tests_result(
argv, args, kwargs, xml_reporter.TextAndXMLTestRunner)
sys.exit(not result.wasSuccessful())
示例6: testNoExit
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def testNoExit(self):
result = object()
test = object()
class FakeRunner(object):
def run(self, test):
self.test = test
return result
runner = FakeRunner()
oldParseArgs = unittest.TestProgram.parseArgs
def restoreParseArgs():
unittest.TestProgram.parseArgs = oldParseArgs
unittest.TestProgram.parseArgs = lambda *args: None
self.addCleanup(restoreParseArgs)
def removeTest():
del unittest.TestProgram.test
unittest.TestProgram.test = test
self.addCleanup(removeTest)
program = unittest.TestProgram(testRunner=runner, exit=False, verbosity=2)
self.assertEqual(program.result, result)
self.assertEqual(runner.test, test)
self.assertEqual(program.verbosity, 2)
示例7: test_engine
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def test_engine(engine):
global JSEngine, ctx
print('\nStart test %s' % engine.__name__)
if engine is ExternalJSEngine:
print('Used external interpreter: %r' % jsengine.external_interpreter)
JSEngine = engine
ctx = None
unittest.TestProgram(exit=False)
print('End test %s\n' % engine.__name__)
示例8: test_command_line_handling_parseArgs
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def test_command_line_handling_parseArgs(self):
# Haha - take that uninstantiable class
program = object.__new__(unittest.TestProgram)
args = []
def do_discovery(argv):
args.extend(argv)
program._do_discovery = do_discovery
program.parseArgs(['something', 'discover'])
self.assertEqual(args, [])
program.parseArgs(['something', 'discover', 'foo', 'bar'])
self.assertEqual(args, ['foo', 'bar'])
示例9: test_command_line_handling_do_discovery_too_many_arguments
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def test_command_line_handling_do_discovery_too_many_arguments(self):
class Stop(Exception):
pass
def usageExit():
raise Stop
program = object.__new__(unittest.TestProgram)
program.usageExit = usageExit
program.testLoader = None
with self.assertRaises(Stop):
# too many args
program._do_discovery(['one', 'two', 'three', 'four'])
示例10: test_command_line_handling_do_discovery_uses_default_loader
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def test_command_line_handling_do_discovery_uses_default_loader(self):
program = object.__new__(unittest.TestProgram)
class Loader(object):
args = []
def discover(self, start_dir, pattern, top_level_dir):
self.args.append((start_dir, pattern, top_level_dir))
return 'tests'
program.testLoader = Loader()
program._do_discovery(['-v'])
self.assertEqual(Loader.args, [('.', 'test*.py', None)])
示例11: testmain
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def testmain(*args, **kw):
new_kw = kw.copy()
if 'testLoader' not in new_kw:
new_kw['testLoader'] = TestLoader()
program_class = new_kw.get('testProgram', TestProgram)
program_class(*args, **new_kw)
示例12: run
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def run(*arg, **kw):
"""Collect and run tests, returning success or failure.
The arguments to `run()` are the same as to `main()`:
* module: All tests are in this module (default: None)
* defaultTest: Tests to load (default: '.')
* argv: Command line arguments (default: None; sys.argv is read)
* testRunner: Test runner instance (default: None)
* testLoader: Test loader instance (default: None)
* env: Environment; ignored if config is provided (default: None;
os.environ is read)
* config: :class:`nose.config.Config` instance (default: None)
* suite: Suite or list of tests to run (default: None). Passing a
suite or lists of tests will bypass all test discovery and
loading. *ALSO NOTE* that if you pass a unittest.TestSuite
instance as the suite, context fixtures at the class, module and
package level will not be used, and many plugin hooks will not
be called. If you want normal nose behavior, either pass a list
of tests, or a fully-configured :class:`nose.suite.ContextSuite`.
* plugins: List of plugins to use; ignored if config is provided
(default: load plugins with DefaultPluginManager)
* addplugins: List of **extra** plugins to use. Pass a list of plugin
instances in this argument to make custom plugins available while
still using the DefaultPluginManager.
With the exception that the ``exit`` argument is always set
to False.
"""
kw['exit'] = False
return TestProgram(*arg, **kw).success
示例13: runmodule
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def runmodule(name='__main__', **kw):
"""Collect and run tests in a single module only. Defaults to running
tests in __main__. Additional arguments to TestProgram may be passed
as keyword arguments.
"""
main(defaultTest=name, **kw)
示例14: _generate_ending
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def _generate_ending(self):
return self.ENDING_TMPL
##############################################################################
# Facilities for running tests from the command line
##############################################################################
# Note: Reuse unittest.TestProgram to launch test. In the future we may
# build our own launcher to support more specific command line
# parameters like test title, CSS, etc.
示例15: runTests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import TestProgram [as 别名]
def runTests(self):
# Pick HTMLTestRunner as the default test runner.
# base class's testRunner parameter is not useful because it means
# we have to instantiate HTMLTestRunner before we know self.verbosity.
if self.testRunner is None:
self.testRunner = HTMLTestRunner(verbosity=self.verbosity)
unittest.TestProgram.runTests(self)