本文整理汇总了Python中unittest.TextTestRunner类的典型用法代码示例。如果您正苦于以下问题:Python TextTestRunner类的具体用法?Python TextTestRunner怎么用?Python TextTestRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextTestRunner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: all
def all():
'''
This runs all tests and examples. It is something of a compromise - seems
to be the best solution that's independent of other libraries, doesn't
use the file system (since code may be in a zip file), and keeps the
number of required imports to a minimum.
'''
basicConfig(level=ERROR)
log = getLogger('lepl._test.all.all')
suite = TestSuite()
loader = TestLoader()
runner = TextTestRunner(verbosity=4)
for module in ls_modules(lepl, MODULES):
log.debug(module.__name__)
suite.addTest(loader.loadTestsFromModule(module))
result = runner.run(suite)
print('\n\n\n----------------------------------------------------------'
'------------\n')
if version[0] == '2':
print('Expect 2-5 failures + 2 errors in Python 2: {0:d}, {1:d} '
.format(len(result.failures), len(result.errors)))
assert 2 <= len(result.failures) <= 5, len(result.failures)
assert 1 <= len(result.errors) <= 2, len(result.errors)
target = TOTAL - NOT_DISTRIBUTED - NOT_3
else:
print('Expect at most 1 failure + 0 errors in Python 3: {0:d}, {1:d} '
.format(len(result.failures), len(result.errors)))
assert 0 <= len(result.failures) <= 1, len(result.failures)
assert 0 <= len(result.errors) <= 0, len(result.errors)
target = TOTAL - NOT_DISTRIBUTED
print('Expect {0:d} tests total: {1:d}'.format(target, result.testsRun))
assert result.testsRun == target, result.testsRun
print('\nLooks OK to me!\n\n')
开发者ID:gcarothers,项目名称:lepl,代码行数:33,代码来源:__init__.py
示例2: __init__
def __init__(self, output='.', stream=sys.stderr, descriptions=True, \
verbose=False, elapsed_times=True):
"Create a new instance of XMLTestRunner."
verbosity = (1, 2)[verbose]
TextTestRunner.__init__(self, stream, descriptions, verbosity)
self.output = output
self.elapsed_times = elapsed_times
开发者ID:garsue,项目名称:unittest-xml-reporting,代码行数:7,代码来源:__init__.py
示例3: main
def main() -> None:
u"""Главная функция.
:return: list набор выполненных тестов
"""
test_runner, ssh = TextTestRunner(), SSHClient()
result = test_runner.run(test_suites.connection_suite(ssh))
开发者ID:gitter-badger,项目名称:CLI-1,代码行数:7,代码来源:test.py
示例4: run
def run(self):
'''
Finds all the tests modules in tests/, and runs them, exiting after they are all done
'''
from tests.server import TestServer
from tests.test_core import WebserviceTest
log.set_verbosity(self.verbose)
if self.verbose >= 2:
self.announce('Setting log level to DEBUG ({0})'.format(logging.DEBUG), level = 2)
logging.basicConfig(level = logging.DEBUG)
testfiles = [ ]
if self.testmodule is None:
for t in glob(pjoin(self._dir, 'tests', self.test_prefix + '*.py')):
if not t.endswith('__init__.py'):
testfiles.append('.'.join(['tests', splitext(basename(t))[0]]))
else:
testfiles.append(self.testmodule)
server = TestServer(daemonise = True, silent = (self.verbose < 3))
server.start()
WebserviceTest.TEST_PORT = server.port
self.announce("Waiting for test server to start on port " + str(server.port), level=2)
time.sleep(1)
self.announce("Test files:" + str(testfiles), level=2)
tests = TestLoader().loadTestsFromNames(testfiles)
t = TextTestRunner(verbosity = self.verbose)
result = t.run(tests)
failed, errored = map(len, (result.failures, result.errors))
exit(failed + errored)
开发者ID:intermine,项目名称:intermine-ws-client.py,代码行数:33,代码来源:setup.py
示例5: run
def run(self):
where = os.path.join('pythran', 'tests')
try:
import py
import xdist
import multiprocessing
cpu_count = multiprocessing.cpu_count()
args = ["-n", str(cpu_count), where]
if self.failfast:
args.insert(0, '-x')
if self.cov:
try:
import pytest_cov
args = ["--cov-report", "html",
"--cov-report", "annotate",
"--cov", "pythran"] + args
except ImportError:
print ("W: Skipping coverage analysis, pytest_cov"
"not found")
py.test.cmdline.main(args)
except ImportError:
print ("W: Using only one thread, "
"try to install pytest-xdist package")
loader = TestLoader()
t = TextTestRunner(failfast=self.failfast)
t.run(loader.discover(where))
开发者ID:franckCJ,项目名称:pythran,代码行数:26,代码来源:setup.py
示例6: run
def run(self):
try:
# Use system 'coverage' if available
import coverage
use_coverage = True
except:
use_coverage = False
tests = TestLoader().loadTestsFromNames(self._testfiles)
t = TextTestRunner(verbosity=1)
if use_coverage:
coverage.erase()
coverage.start()
if hasattr(unittest, "installHandler"):
try:
unittest.installHandler()
except:
print "installHandler hack failed"
try:
result = t.run(tests)
except KeyboardInterrupt:
sys.exit(1)
if use_coverage:
coverage.stop()
sys.exit(int(bool(len(result.failures) > 0 or
len(result.errors) > 0)))
开发者ID:tomlanyon,项目名称:python-virtinst,代码行数:31,代码来源:setup.py
示例7: run
def run(self):
"""
Finds all the tests modules in test/, and runs them.
"""
exclude = [pjoin(self._dir, 'test', 'cern_sso_auth_t.py')]
testfiles = []
for t in glob(pjoin(self._dir, 'test', '*_t.py')):
if not t.endswith('__init__.py') and t not in exclude:
testfiles.append('.'.join(
['test', splitext(basename(t))[0]])
)
testfiles.sort()
try:
tests = TestLoader().loadTestsFromNames(testfiles)
except Exception as exc:
print("\nFail to load unit tests", testfiles)
# check which tests are failing to get imported
for test in testfiles:
try:
print("trying to import:", test)
__import__(test)
except Exception as import_err:
print("failed importing: ", test, import_err)
print(exc)
raise exc
t = TextTestRunner(verbosity = 2)
result = t.run(tests)
# return a non-zero exit status on failure -- useful in CI
if not result.wasSuccessful():
sys.exit(1)
开发者ID:dmwm,项目名称:DAS,代码行数:30,代码来源:setup.py
示例8: run
def run(self):
# Do not include current directory, validate using installed pythran
current_dir = _exclude_current_dir_from_import()
os.chdir("pythran/tests")
where = os.path.join(current_dir, 'pythran')
from pythran import test_compile
test_compile()
try:
import py
import xdist
args = ["-n", str(self.num_threads), where, '--pep8']
if self.failfast:
args.insert(0, '-x')
if self.cov:
try:
import pytest_cov
args = ["--cov-report", "html",
"--cov-report", "annotate",
"--cov", "pythran"] + args
except ImportError:
print ("W: Skipping coverage analysis, pytest_cov"
"not found")
if py.test.cmdline.main(args) == 0:
print "\\_o<"
except ImportError:
print ("W: Using only one thread, "
"try to install pytest-xdist package")
loader = TestLoader()
t = TextTestRunner(failfast=self.failfast)
t.run(loader.discover(where))
if t.wasSuccessful():
print "\\_o<"
开发者ID:baoboa,项目名称:pythran,代码行数:34,代码来源:setup.py
示例9: run
def run(self):
'''
Finds all the tests modules in tests/, and runs them.
'''
if self.coverage:
cov = TestCoverage()
cov.start()
testfiles = [ ]
for t in glob(pjoin(self._dir, 'tests', '*.py')):
if not t.endswith('__init__.py'):
testfiles.append('.'.join(
['tests', splitext(basename(t))[0]])
)
tests = TestLoader().loadTestsFromNames(testfiles)
t = TextTestRunner(verbosity = 1)
ts = t.run(tests)
if self.coverage:
cov.stop()
cov.report()
if not ts.wasSuccessful():
sys.exit(1)
开发者ID:frogbywyplay,项目名称:genbox_xov,代码行数:25,代码来源:setup.py
示例10: run
def run(self):
'''
Finds all the tests modules in tests/, and runs them, exiting after they are all done
'''
from tests.testserver import TestServer
from tests.test import WebserviceTest
log.set_verbosity(self.verbose)
server = TestServer()
server.start()
WebserviceTest.TEST_PORT = server.port
self.announce("Waiting for test server to start on port " + str(server.port), level=2)
time.sleep(1)
testfiles = [ ]
for t in glob(pjoin(self._dir, 'tests', self.test_prefix + '*.py')):
if not t.endswith('__init__.py'):
testfiles.append('.'.join(
['tests', splitext(basename(t))[0]])
)
self.announce("Test files:" + str(testfiles), level=2)
tests = TestLoader().loadTestsFromNames(testfiles)
t = TextTestRunner(verbosity = self.verbose)
t.run(tests)
exit()
开发者ID:kkarra,项目名称:intermine-ws-client.py,代码行数:28,代码来源:setup.py
示例11: run
def run(self):
"""
Finds and executes unit tests in the 'tests' subdir.
Because TestLoader imports the tests as a module this method
automatically creates/updates the 'tests/__init__.py' to
import all python scripts in the 'tests' subdir.
"""
self.run_command('build')
sys.path.insert(0,os.path.join(os.getcwd(),"build","lib"))
self.tests = []
# make sure the 'tests' subdir actually exists.
if not os.path.isdir(self.tests_dir):
print "ExecuteTests: <Error> 'tests' subdir not found!"
else:
self.find_tests()
self.gen_tests_init()
# create a test suite.
tests = TestLoader().loadTestsFromNames([t[0] for t in self.tests])
if not self.filter is None:
tests = self.filter_tests(tests)
# run the test suite if it actually contains test cases.
run_verbosity = 2
if self.verbose == 0:
run_verbosity = 0
if tests.countTestCases() > 0:
runner = TextTestRunner(verbosity=run_verbosity)
runner.run(tests)
else:
print "ExecuteTests: <Warning> No test cases found!"
sys.path.pop(0)
开发者ID:ahota,项目名称:visit_intel,代码行数:30,代码来源:setup_tests.py
示例12: run
def run(self):
sys.path.insert(0, os.path.join(root_dir, package_dir))
sys.path.insert(0, os.path.join(root_dir, test_dir))
os.chdir(test_dir)
import all_tests
t = TextTestRunner(verbosity=2)
t.run(all_tests.suite())
开发者ID:mosaic-data-model,项目名称:mosaic-python,代码行数:7,代码来源:setup.py
示例13: run
def run(self):
sys.path.insert(0, os.path.join(self._dir, BOKEEP_SRC_DIR) )
sys.path.insert(0, os.path.join(self._dir, 'tests') )
tests = list(self.generate_test_files())
tests = TestLoader().loadTestsFromNames( tests )
t = TextTestRunner(verbosity = 1)
t.run(tests)
开发者ID:paritworkercoop,项目名称:bokeep-mirror,代码行数:7,代码来源:setup.py
示例14: main
def main():
my_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.abspath(os.path.join(my_dir, '..')))
has_pep8 = False
try:
import pep8
has_pep8 = True
except ImportError:
if '--with-pep8' in sys.argv[1:]:
sys.stderr.write('# Could not find pep8 library.')
sys.exit(1)
if has_pep8:
guide = pep8.StyleGuide(
ignore=[],
paths=['wtforms/'],
exclude=['wtforms/ext/sqlalchemy', 'wtforms/ext/appengine'],
max_line_length=130,
)
report = guide.check_files()
if report.total_errors:
sys.exit(1)
extra_tests = tuple(x for x in sys.argv[1:] if '-' not in x)
suite = make_suite('', extra_tests)
runner = TextTestRunner(verbosity=(sys.argv.count('-v') - sys.argv.count('-q') + 1))
result = runner.run(suite)
sys.exit(not result.wasSuccessful())
开发者ID:andymccurdy,项目名称:wtforms,代码行数:29,代码来源:runtests.py
示例15: _run_tests
def _run_tests(self):
secrets_current = pjoin(self._dir, 'rtwo/test', 'secrets.py')
secrets_dist = pjoin(self._dir, 'rtwo/test', 'secrets.py.dist')
if not os.path.isfile(secrets_current):
print("Missing " + secrets_current)
print("Maybe you forgot to copy it from .dist:")
print("cp rtwo/test/secrets.py.dist rtwo/test/secrets.py")
sys.exit(1)
mtime_current = os.path.getmtime(secrets_current)
mtime_dist = os.path.getmtime(secrets_dist)
if mtime_dist > mtime_current:
print("It looks like test/secrets.py file is out of date.")
print("Please copy the new secrets.py.dist file over otherwise" +
" tests might fail")
testfiles = []
for test_path in TEST_PATHS:
for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
testfiles.append('.'.join(
[test_path.replace('/', '.'), splitext(basename(t))[0]]))
tests = TestLoader().loadTestsFromNames(testfiles)
t = TextTestRunner(verbosity=2)
res = t.run(tests)
return not res.wasSuccessful()
开发者ID:cdosborn,项目名称:rtwo,代码行数:28,代码来源:setup.py
示例16: RunTest
def RunTest(test):
global TestLoader, TextTestRunner
testItem = TestLoader().loadTestsFromTestCase(test)
res = TextTestRunner(verbosity=2).run(testItem)
if not res.wasSuccessful():
raise Exception("Unit test failed")
开发者ID:deniskoronchik,项目名称:sc-machine,代码行数:7,代码来源:sc_test.py
示例17: __init__
def __init__(self, output="./reports/", verbosity=2, stream=sys.stderr,
descriptions=True, failfast=False, buffer=False,
report_title=None, report_name=None, template=None, resultclass=None,
add_timestamp=True, open_in_browser=False,
combine_reports=False, template_args=None):
self.verbosity = verbosity
self.output = output
self.encoding = UTF8
TextTestRunner.__init__(self, stream, descriptions, verbosity,
failfast=failfast, buffer=buffer)
if add_timestamp:
self.timestamp = time.strftime(self.time_format)
else:
self.timestamp = ""
if resultclass is None:
self.resultclass = HtmlTestResult
else:
self.resultclass = resultclass
if template_args is not None and not isinstance(template_args, dict):
raise ValueError("template_args must be a dict-like.")
self.template_args = template_args or {}
self.report_title = report_title or "Unittest Results"
self.report_name = report_name
self.template = template
self.open_in_browser = open_in_browser
self.combine_reports = combine_reports
self.start_time = 0
self.time_taken = 0
开发者ID:oldani,项目名称:HtmlTestRunner,代码行数:35,代码来源:runner.py
示例18: main
def main():
suite = TestSuite()
suite.addTest(ParserTest("test_parser"))
suite.addTest(DirectiveTestDate("test_regexp"))
suite.addTest(DirectiveTestDate("test_format"))
runner = TextTestRunner()
runner.run(suite)
开发者ID:NonterransMiner,项目名称:LogPre,代码行数:7,代码来源:log4j.py
示例19: run_tests
def run_tests():
suite = TestSuite()
suite.addTest(TestRAVerification('test_verify_prefix'))
suite.addTest(TestRAVerification('test_verify_cert'))
suite.addTest(TestRAVerification('test_verify_signature'))
runner = TextTestRunner()
runner.run(suite)
开发者ID:heavilessrose,项目名称:TrustRouter,代码行数:7,代码来源:__init__.py
示例20: main
def main():
my_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.abspath(os.path.join(my_dir, '..')))
from optparse import OptionParser
parser = OptionParser()
parser.add_option('--with-pep8', action='store_true', dest='with_pep8',
default=True)
parser.add_option('--with-pyflakes', action='store_true',
dest='with_pyflakes', default=True)
parser.add_option('--force-all', action='store_true', dest='force_all',
default=False)
parser.add_option('-v', '--verbose', action='count', dest='verbosity',
default=0)
parser.add_option('-q', '--quiet', action='count', dest='quietness',
default=0)
options, extra_args = parser.parse_args()
if options.with_pep8:
try:
import pep8
except ImportError:
sys.stderr.write('# Could not find pep8 library.\n')
sys.exit(1)
guide_main = pep8.StyleGuide(
ignore=[],
paths=['subte/'],
exclude=[],
max_line_length=80,
)
guide_tests = pep8.StyleGuide(
ignore=['E221'],
paths=['tests/'],
max_line_length=80,
)
for guide in (guide_main, guide_tests):
report = guide.check_files()
if report.total_errors:
sys.exit(1)
if options.with_pyflakes:
try:
import pyflakes
assert pyflakes # silence pyflakes
except ImportError:
sys.stderr.write('# Could not find pyflakes library.\n')
sys.exit(1)
from pyflakes import api, reporter
warnings = api.checkRecursive(['subte', 'tests'],
reporter._makeDefaultReporter())
if warnings > 0:
sys.exit(1)
suite = make_suite('', tuple(extra_args), options.force_all)
runner = TextTestRunner(verbosity=options.verbosity - options.quietness + 1)
result = runner.run(suite)
sys.exit(not result.wasSuccessful())
开发者ID:juancarlosfarah,项目名称:subte-utilities,代码行数:59,代码来源:runtests.py
注:本文中的unittest.TextTestRunner类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论