本文整理汇总了Python中xmlrunner.XMLTestRunner方法的典型用法代码示例。如果您正苦于以下问题:Python xmlrunner.XMLTestRunner方法的具体用法?Python xmlrunner.XMLTestRunner怎么用?Python xmlrunner.XMLTestRunner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrunner
的用法示例。
在下文中一共展示了xmlrunner.XMLTestRunner方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def test(coverage=False):
"""Run the unit tests."""
if coverage and not os.environ.get('FLASK_COVERAGE'):
import sys
os.environ['FLASK_COVERAGE'] = '1'
os.execvp(sys.executable, [sys.executable] + sys.argv)
import unittest
import xmlrunner
tests = unittest.TestLoader().discover('tests')
# run tests with unittest-xml-reporting and output to $CIRCLE_TEST_REPORTS on CircleCI or test-reports locally
xmlrunner.XMLTestRunner(output=os.environ.get('CIRCLE_TEST_REPORTS','test-reports')).run(tests)
if COV:
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
basedir = os.path.abspath(os.path.dirname(__file__))
covdir = os.path.join(basedir, 'tmp/coverage')
COV.html_report(directory=covdir)
print('HTML version: file://%s/index.html' % covdir)
COV.erase()
示例2: run_suite
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def run_suite(self, suite, **kwargs):
dummy = kwargs # unused
verbosity = getattr(settings, 'TEST_OUTPUT_VERBOSE', 1)
# XXX: verbosity = self.verbosity
if isinstance(verbosity, bool):
verbosity = (1, 2)[verbosity]
descriptions = getattr(settings, 'TEST_OUTPUT_DESCRIPTIONS', False)
output_dir = getattr(settings, 'TEST_OUTPUT_DIR', '.')
single_file = getattr(settings, 'TEST_OUTPUT_FILE_NAME', None)
kwargs = dict(
verbosity=verbosity, descriptions=descriptions,
failfast=self.failfast)
if single_file is not None:
file_path = os.path.join(output_dir, single_file)
with open(file_path, 'wb') as xml:
return xmlrunner.XMLTestRunner(
output=xml, **kwargs).run(suite)
else:
return xmlrunner.XMLTestRunner(
output=output_dir, **kwargs).run(suite)
示例3: main
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def main():
root_url = os.environ['INFRABOX_ROOT_URL']
print "ROOT_URL: %s" % root_url
while True:
time.sleep(1)
r = None
try:
r = requests.get(root_url, verify=False)
if r.status_code in (200, 404):
break
print r.text
except Exception as e:
print e
print "Server not yet ready"
print "Connecting to DB"
connect_db() # Wait for DB
print "Starting tests"
with open('results.xml', 'wb') as output:
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), buffer=False)
示例4: test
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def test(coverage=False):
"""Run the unit tests."""
import sys
if coverage and not os.environ.get('FLASK_COVERAGE'):
os.environ['FLASK_COVERAGE'] = '1'
os.execvp(sys.executable, [sys.executable] + sys.argv)
import unittest
import xmlrunner
tests = unittest.TestLoader().discover('tests')
results = xmlrunner.XMLTestRunner(output='test-reports').run(tests)
if COV:
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
basedir = os.path.abspath(os.path.dirname(__file__))
covdir = os.path.join(basedir, 'test-reports/coverage')
COV.html_report(directory=covdir)
print('HTML version: file://%s/index.html' % covdir)
COV.erase()
if (len(results.failures) > 0 or len(results.errors) > 0):
sys.exit(1)
示例5: run_tests
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def run_tests(suite=None, xmloutput=None, verbosity=1):
"""
args
----
- suite [TestSuite]
A suite of all tests to run
- xmloutput [str or None]
Path of XML output directory (optional)
- verbosity [int]
Verbosity level of tests output
Returns the TestResult object after running the test *suite*.
"""
if suite is None:
suite = discover_tests("llvmlite.tests")
if xmloutput is not None:
import xmlrunner
runner = xmlrunner.XMLTestRunner(output=xmloutput)
else:
runner = None
prog = unittest.main(suite=suite, testRunner=runner, exit=False,
verbosity=verbosity)
return prog.result
示例6: runtests
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def runtests(xmlrunner=False):
''' Run unit tests '''
import sys
if '--profile' in sys.argv:
import profile
import pstats
sys.argv = [x for x in sys.argv if x != '--profile']
if xmlrunner:
import xmlrunner as xr
profile.run("unittest.main(testRunner=xr.XMLTestRunner(output='test-reports', verbosity=2))", '_stats.txt')
else:
profile.run('unittest.main()', '_stats.txt')
stats = pstats.Stats('_stats.txt')
#stats.strip_dirs()
stats.sort_stats('cumulative', 'calls')
stats.print_stats(25)
stats.sort_stats('time', 'calls')
stats.print_stats(25)
elif xmlrunner:
import xmlrunner as xr
unittest.main(testRunner=xr.XMLTestRunner(output='test-reports', verbosity=2))
else:
unittest.main()
示例7: main
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def main():
if not os.path.isfile('run_tests.py'):
print('Please execute from a `tests` directory!')
return 1
else:
runner = XMLTestRunner(verbosity=2, output='results')
# tests = unittest.TestLoader().discover('.', pattern='test*.py')
tests = unittest.TestSuite()
tests.addTest(test_scenarios.RequestsTesingUsingScenarios())
tests.addTest(test_arguments.ArgumentsTest())
result = runner.run(tests)
if result.wasSuccessful():
return 0
else:
return 1
示例8: main
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def main():
root_url = os.environ['INFRABOX_ROOT_URL']
urllib3.disable_warnings()
print("Connecting to DB")
connect_db() # Wait for DB
print("ROOT_URL: %s" % root_url)
while True:
time.sleep(1)
r = None
try:
r = requests.get(root_url, verify=False)
if r.status_code in (200, 404):
break
print(r.text)
except Exception as e:
print(e)
print("Server not yet ready")
time.sleep(90)
print("Starting tests")
with open('results.xml', 'wb') as output:
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), buffer=False)
示例9: configure
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def configure(self, options):
'''configure before testing'''
self.test_options = options
if options.xunit:
try:
from xmlrunner import XMLTestRunner
except ImportError:
raise Exception("unittest-xml-reporting not installed")
self.runner = XMLTestRunner(stream=sys.stderr, \
verbosity=2, output=options.xunit)
else:
self.runner = unittest.TextTestRunner(stream=sys.stderr, \
verbosity=2)
if options.manifest:
fbname, fext = os.path.splitext(os.path.basename(options.manifest))
assert fbname == "manifest" or fext == ".manifest", \
"Please specify file name like xxx.manifest or manifest.xxx"
self.tclist = self.__get_tc_from_manifest(options.manifest)
if options.tests:
tcs = [t[0:-3] if t.endswith(".py") else t[0:-1] \
if t.endswith("/") else t for t in options.tests]
self.tclist.extend([tc.replace("/", ".") for tc in tcs])
if options.logdir:
logdir = self._get_log_dir(options.logdir)
self.log_handler = LogHandler(logdir)
try:
self.context.def_timeout = int(options.timeout)
except ValueError:
print "timeout need an integer value"
raise
示例10: handle
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def handle(self, *args, **opts):
suite = unittest.TestSuite()
for root in map(module_path, self.modules):
for arg in args or ["*"]:
suite.addTests(
unittest.defaultTestLoader.discover(root, pattern=arg, top_level_dir=root)
)
# verbosity > 1 print test name
verbosity = opts.get("verbosity")
xml_path = opts.get("xml_output_dir")
# if opts.get('produce_xml'):
if xml_path is not None or opts.get("produce_xml"):
import xmlrunner
runner = xmlrunner.XMLTestRunner(
output=xml_path or "test-reports", verbosity=verbosity
)
else:
runner = unittest.TextTestRunner(verbosity=verbosity)
result = runner.run(suite)
if not result.wasSuccessful():
sys.exit(1)
示例11: main
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def main():
tests = unittest.TestLoader().discover(".", "test_*.py")
testResult = xmlrunner.XMLTestRunner(
output=str(Path(".").resolve() / "test-reports")
).run(tests)
return not testResult.wasSuccessful()
示例12: main
# 需要导入模块: import xmlrunner [as 别名]
# 或者: from xmlrunner import XMLTestRunner [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-t", help="Test case(s) to run")
parser.add_argument("-d", help="Directory to choose tests from")
parser.add_argument("-f", help="Find the test cases from the file")
parser.add_argument("-c", help="The (yaml) config file to use",
default="config.yml")
parser.add_argument("-j", help="Directory to store JUnit XML file",
action="store",
dest="xmldir")
args = parser.parse_args()
_ = distaf_init(args.c)
if args.f != None:
collect_tests(args.f)
set_tests()
elif args.d != None and args.t != None:
collect_tests("tests_d/%s" % args.d)
set_tests(args.t.split(' '))
elif args.t != None:
collect_tests()
set_tests(args.t.split(' '))
elif args.d != None:
collect_tests("tests_d/%s" % args.d)
set_tests()
else:
collect_tests()
set_tests()
get_num = lambda x: int(re.search(r'test_([0-9]+)_', x).group(1))
sortcmp = lambda _, x, y: cmp(get_num(x), get_num(y))
unittest.TestLoader.sortTestMethodsUsing = sortcmp
if args.xmldir != None:
import xmlrunner
runner = xmlrunner.XMLTestRunner(output=args.xmldir)
else:
runner = unittest.TextTestRunner(verbosity=2)
itersuite = unittest.TestLoader().loadTestsFromTestCase(gluster_tests)
runner.run(itersuite)
distaf_finii()