本文整理汇总了Python中behave.log_capture.LoggingCapture.abandon方法的典型用法代码示例。如果您正苦于以下问题:Python LoggingCapture.abandon方法的具体用法?Python LoggingCapture.abandon怎么用?Python LoggingCapture.abandon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类behave.log_capture.LoggingCapture
的用法示例。
在下文中一共展示了LoggingCapture.abandon方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ModelRunner
# 需要导入模块: from behave.log_capture import LoggingCapture [as 别名]
# 或者: from behave.log_capture.LoggingCapture import abandon [as 别名]
#.........这里部分代码省略.........
if self.config.log_capture:
self.log_capture = LoggingCapture(self.config)
self.log_capture.inveigle()
self.context.log_capture = self.log_capture
def start_capture(self):
if self.config.stdout_capture:
# -- REPLACE ONLY: In non-capturing mode.
if not self.old_stdout:
self.old_stdout = sys.stdout
sys.stdout = self.stdout_capture
assert sys.stdout is self.stdout_capture
if self.config.stderr_capture:
# -- REPLACE ONLY: In non-capturing mode.
if not self.old_stderr:
self.old_stderr = sys.stderr
sys.stderr = self.stderr_capture
assert sys.stderr is self.stderr_capture
def stop_capture(self):
if self.config.stdout_capture:
# -- RESTORE ONLY: In capturing mode.
if self.old_stdout:
sys.stdout = self.old_stdout
self.old_stdout = None
assert sys.stdout is not self.stdout_capture
if self.config.stderr_capture:
# -- RESTORE ONLY: In capturing mode.
if self.old_stderr:
sys.stderr = self.old_stderr
self.old_stderr = None
assert sys.stderr is not self.stderr_capture
def teardown_capture(self):
if self.config.log_capture:
self.log_capture.abandon()
def run_model(self, features=None):
if not self.context:
self.context = Context(self)
if features is None:
features = self.features
# -- ENSURE: context.execute_steps() works in weird cases (hooks, ...)
context = self.context
self.setup_capture()
self.run_hook('before_all', context)
run_feature = not self.aborted
failed_count = 0
undefined_steps_initial_size = len(self.undefined_steps)
for feature in features:
if run_feature:
try:
self.feature = feature
for formatter in self.formatters:
formatter.uri(feature.filename)
tries = int(self.config.retry_count)
failed = True
while failed and tries > 0:
failed = feature.run(self)
tries -= 1
if failed:
failed_count += 1
if self.config.stop or self.aborted:
# -- FAIL-EARLY: After first failure.
run_feature = False
except KeyboardInterrupt:
self.aborted = True
failed_count += 1
run_feature = False
# -- ALWAYS: Report run/not-run feature to reporters.
# REQUIRED-FOR: Summary to keep track of untested features.
for reporter in self.config.reporters:
reporter.feature(feature)
# -- AFTER-ALL:
if self.aborted:
print("\nABORTED: By user.")
for formatter in self.formatters:
formatter.close()
self.run_hook('after_all', self.context)
for reporter in self.config.reporters:
reporter.end()
# if self.aborted:
# print("\nABORTED: By user.")
failed = ((failed_count > 0) or self.aborted or
(len(self.undefined_steps) > undefined_steps_initial_size))
return failed
def run(self):
"""
Implements the run method by running the model.
"""
self.context = Context(self)
return self.run_model()
示例2: Runner
# 需要导入模块: from behave.log_capture import LoggingCapture [as 别名]
# 或者: from behave.log_capture.LoggingCapture import abandon [as 别名]
#.........这里部分代码省略.........
sys.path.pop(0)
def run_hook(self, name, context, *args):
if not self.config.dry_run and (name in self.hooks):
with context.user_mode():
self.hooks[name](context, *args)
def feature_files(self):
files = []
for path in self.config.paths:
if os.path.isdir(path):
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith('.feature'):
files.append(os.path.join(dirpath, filename))
elif path.startswith('@'):
files.extend([filename.strip() for filename in open(path)])
elif os.path.exists(path):
files.append(path)
else:
raise Exception("Can't find path: " + path)
return files
def run(self):
with self.path_manager:
self.setup_paths()
return self.run_with_paths()
def run_with_paths(self):
self.load_hooks()
self.load_step_definitions()
context = self.context = Context(self)
stream = self.config.output
failed = False
self.run_hook('before_all', context)
for filename in self.feature_files():
if self.config.exclude(filename):
continue
feature = parser.parse_file(os.path.abspath(filename),
language=self.config.lang)
self.features.append(feature)
self.feature = feature
self.formatter = formatters.get_formatter(self.config, stream)
self.formatter.uri(filename)
failed |= feature.run(self)
self.formatter.close()
stream.write('\n')
[reporter.feature(feature) for reporter in self.config.reporters]
if failed and self.config.stop:
break
self.run_hook('after_all', context)
[reporter.end() for reporter in self.config.reporters]
return failed
def setup_capture(self):
if self.config.stdout_capture:
self.stdout_capture = StringIO.StringIO()
self.context.stdout_capture = self.stdout_capture
if self.config.stderr_capture:
self.stderr_capture = StringIO.StringIO()
self.context.stderr_capture = self.stderr_capture
if self.config.log_capture:
self.log_capture = LoggingCapture(self.config)
self.log_capture.inveigle()
self.context.log_capture = self.log_capture
def start_capture(self):
if self.config.stdout_capture:
self.old_stdout = sys.stdout
sys.stdout = self.stdout_capture
if self.config.stderr_capture:
self.old_stderr = sys.stderr
sys.stderr = self.stderr_capture
def stop_capture(self):
if self.config.stdout_capture:
sys.stdout = self.old_stdout
if self.config.stderr_capture:
sys.stderr = self.old_stderr
def teardown_capture(self):
if self.config.log_capture:
self.log_capture.abandon()
示例3: Runner
# 需要导入模块: from behave.log_capture import LoggingCapture [as 别名]
# 或者: from behave.log_capture.LoggingCapture import abandon [as 别名]
#.........这里部分代码省略.........
error_string += "<![CDATA[\n"
error_string += failed_step.error_message
error_string += "]]>\n</error>"
return error_string
def write_paralleltestresults_to_junitfile(self,junit_report_objs):
feature_reports = {}
for jro in junit_report_objs:
#NOTE: There's an edge-case where this key would not be unique
#Where a feature has the same filename and feature name but
#different directory.
uniquekey = jro['filebasename']+"."+jro['feature_name']
if uniquekey not in feature_reports:
newfeature = {}
newfeature['duration'] = float(jro['duration'])
newfeature['statuses'] = jro['status']
newfeature['filebasename'] = jro['filebasename']
newfeature['total_scenarios'] = 1
newfeature['data'] = jro['report_string']
feature_reports[uniquekey] = newfeature
else:
feature_reports[uniquekey]['duration'] += float(jro['duration'])
feature_reports[uniquekey]['statuses'] += jro['status']
feature_reports[uniquekey]['total_scenarios'] += 1
feature_reports[uniquekey]['data'] += jro['report_string']
for uniquekey in list(feature_reports.keys()):
filedata = "<?xml version='1.0' encoding='UTF-8'?>\n"
filedata += '<testsuite errors="'
filedata += str(len(re.findall\
("failed",feature_reports[uniquekey]['statuses'])))
filedata += '" failures="0" name="'
filedata += uniquekey+'" '
filedata += 'skipped="'
filedata += str(len(re.findall\
("skipped",feature_reports[uniquekey]['statuses'])))
filedata += '" tests="'
filedata += str(feature_reports[uniquekey]['total_scenarios'])
filedata += '" time="'
filedata += str(round(feature_reports[uniquekey]['duration'],4))
filedata += '">'
filedata += "\n\n"
filedata += feature_reports[uniquekey]['data']
filedata += "</testsuite>"
outputdir = "reports"
custdir = getattr(self.config,'junit_directory')
if custdir:
outputdir = custdir
if not os.path.exists(outputdir):
os.makedirs(outputdir)
filename = outputdir+"/"+"TESTS-"
filename += feature_reports[uniquekey]['filebasename']
filename += ".xml"
fd = open(filename,"wb")
fd.write(filedata.encode('utf8'))
fd.close()
def setup_capture(self):
if self.config.stdout_capture:
self.stdout_capture = io.StringIO()
self.context.stdout_capture = self.stdout_capture
if self.config.stderr_capture:
self.stderr_capture = io.StringIO()
self.context.stderr_capture = self.stderr_capture
if self.config.log_capture:
self.log_capture = LoggingCapture(self.config)
self.log_capture.inveigle()
self.context.log_capture = self.log_capture
def start_capture(self):
if self.config.stdout_capture:
self.old_stdout = sys.stdout
sys.stdout = self.stdout_capture
if self.config.stderr_capture:
self.old_stderr = sys.stderr
sys.stderr = self.stderr_capture
def stop_capture(self):
if self.config.stdout_capture:
sys.stdout = self.old_stdout
if self.config.stderr_capture:
sys.stderr = self.old_stderr
def teardown_capture(self):
if self.config.log_capture:
self.log_capture.abandon()
# def clean_buffer(self, buf):
# for i in range(len(buf.buflist)):
# buf.buflist[i] = self.to_unicode(buf.buflist[i])
@staticmethod
def to_unicode(var):
string = str(var) if isinstance(var, int) else var
return str(string) if isinstance(string, str) else string
示例4: Runner
# 需要导入模块: from behave.log_capture import LoggingCapture [as 别名]
# 或者: from behave.log_capture.LoggingCapture import abandon [as 别名]
#.........这里部分代码省略.........
sys.path.pop(0)
def run_hook(self, name, context, *args):
if not self.config.dry_run and (name in self.hooks):
with context.user_mode():
self.hooks[name](context, *args)
def feature_files(self):
return collect_feature_files(self.config.paths)
def run(self):
with self.path_manager:
self.setup_paths()
return self.run_with_paths()
def run_with_paths(self):
self.load_hooks()
self.load_step_definitions()
context = self.context = Context(self)
# -- ENSURE: context.execute_steps() works in weird cases (hooks, ...)
self.setup_capture()
stream_openers = self.config.outputs
failed_count = 0
self.run_hook('before_all', context)
# -- STEP: Parse all feature files.
feature_files = [ filename for filename in self.feature_files()
if not self.config.exclude(filename) ]
features = parse_features(feature_files, language=self.config.lang)
self.features.extend(features)
# -- STEP: Run all features.
self.formatters = formatters.get_formatter(self.config, stream_openers)
undefined_steps_initial_size = len(self.undefined)
run_feature = True
for feature in features:
if run_feature:
self.feature = feature
for formatter in self.formatters:
formatter.uri(feature.filename)
failed = feature.run(self)
if failed:
failed_count += 1
if self.config.stop:
# -- FAIL-EARLY: After first failure.
run_feature = False
# -- ALWAYS: Report run/not-run feature to reporters.
# REQUIRED-FOR: Summary to keep track of untested features.
for reporter in self.config.reporters:
reporter.feature(feature)
# -- AFTER-ALL:
for formatter in self.formatters:
formatter.close()
self.run_hook('after_all', context)
for reporter in self.config.reporters:
reporter.end()
failed = ((failed_count > 0) or
(len(self.undefined) > undefined_steps_initial_size))
return failed
def setup_capture(self):
if self.config.stdout_capture:
self.stdout_capture = StringIO.StringIO()
self.context.stdout_capture = self.stdout_capture
if self.config.stderr_capture:
self.stderr_capture = StringIO.StringIO()
self.context.stderr_capture = self.stderr_capture
if self.config.log_capture:
self.log_capture = LoggingCapture(self.config)
self.log_capture.inveigle()
self.context.log_capture = self.log_capture
def start_capture(self):
if self.config.stdout_capture:
self.old_stdout = sys.stdout
sys.stdout = self.stdout_capture
if self.config.stderr_capture:
self.old_stderr = sys.stderr
sys.stderr = self.stderr_capture
def stop_capture(self):
if self.config.stdout_capture:
sys.stdout = self.old_stdout
if self.config.stderr_capture:
sys.stderr = self.old_stderr
def teardown_capture(self):
if self.config.log_capture:
self.log_capture.abandon()
示例5: Runner
# 需要导入模块: from behave.log_capture import LoggingCapture [as 别名]
# 或者: from behave.log_capture.LoggingCapture import abandon [as 别名]
#.........这里部分代码省略.........
def feature_files(self):
files = []
for path in self.config.paths:
if os.path.isdir(path):
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith('.feature'):
files.append(os.path.join(dirpath, filename))
elif path.startswith('@'):
# -- USE: behave @list_of_features.txt
files.extend(self.parse_features_file(path[1:]))
elif os.path.exists(path):
files.append(path)
else:
raise Exception("Can't find path: " + path)
return files
def run(self):
with self.path_manager:
self.setup_paths()
return self.run_with_paths()
def run_with_paths(self):
self.load_hooks()
self.load_step_definitions()
context = self.context = Context(self)
# -- ENSURE: context.execute_steps() works in weird cases (hooks, ...)
self.setup_capture()
stream = self.config.output
failed = False
failed_count = 0
self.run_hook('before_all', context)
for filename in self.feature_files():
if self.config.exclude(filename):
continue
feature = parser.parse_file(os.path.abspath(filename),
language=self.config.lang)
self.features.append(feature)
self.feature = feature
self.formatter = formatters.get_formatter(self.config, stream)
self.formatter.uri(filename)
failed = feature.run(self)
if failed:
failed_count += 1
self.formatter.close()
for reporter in self.config.reporters:
reporter.feature(feature)
if failed and self.config.stop:
break
self.run_hook('after_all', context)
for reporter in self.config.reporters:
reporter.end()
failed = (failed_count > 0)
return failed
def setup_capture(self):
if self.config.stdout_capture:
self.stdout_capture = StringIO.StringIO()
self.context.stdout_capture = self.stdout_capture
if self.config.stderr_capture:
self.stderr_capture = StringIO.StringIO()
self.context.stderr_capture = self.stderr_capture
if self.config.log_capture:
self.log_capture = LoggingCapture(self.config)
self.log_capture.inveigle()
self.context.log_capture = self.log_capture
def start_capture(self):
if self.config.stdout_capture:
self.old_stdout = sys.stdout
sys.stdout = self.stdout_capture
if self.config.stderr_capture:
self.old_stderr = sys.stderr
sys.stderr = self.stderr_capture
def stop_capture(self):
if self.config.stdout_capture:
sys.stdout = self.old_stdout
if self.config.stderr_capture:
sys.stderr = self.old_stderr
def teardown_capture(self):
if self.config.log_capture:
self.log_capture.abandon()
示例6: Runner
# 需要导入模块: from behave.log_capture import LoggingCapture [as 别名]
# 或者: from behave.log_capture.LoggingCapture import abandon [as 别名]
#.........这里部分代码省略.........
# -- ENSURE: context.execute_steps() works in weird cases (hooks, ...)
self.setup_capture()
self.run_hook('before_all', context)
# -- STEP: Parse all feature files (by using their file location).
feature_locations = [ filename for filename in self.feature_locations()
if not self.config.exclude(filename) ]
features = parse_features(feature_locations, language=self.config.lang)
self.features.extend(features)
# -- STEP: Run all features.
self.formatters = formatters.get_formatter(self.config, stream_openers)
undefined_steps_initial_size = len(self.undefined)
run_feature = True
for feature in features:
if run_feature:
try:
self.feature = feature
for formatter in self.formatters:
formatter.uri(feature.filename)
failed = feature.run(self)
if failed:
failed_count += 1
if self.config.stop or self.aborted:
# -- FAIL-EARLY: After first failure.
run_feature = False
except KeyboardInterrupt:
self.aborted = True
failed_count += 1
run_feature = False
# -- ALWAYS: Report run/not-run feature to reporters.
# REQUIRED-FOR: Summary to keep track of untested features.
for reporter in self.config.reporters:
reporter.feature(feature)
# -- AFTER-ALL:
if self.aborted:
print "\nABORTED: By user."
for formatter in self.formatters:
formatter.close()
self.run_hook('after_all', context)
for reporter in self.config.reporters:
reporter.end()
# if self.aborted:
# print "\nABORTED: By user."
failed = ((failed_count > 0) or self.aborted or
(len(self.undefined) > undefined_steps_initial_size))
return failed
def setup_capture(self):
if self.config.stdout_capture:
self.stdout_capture = StringIO.StringIO()
self.context.stdout_capture = self.stdout_capture
if self.config.stderr_capture:
self.stderr_capture = StringIO.StringIO()
self.context.stderr_capture = self.stderr_capture
if self.config.log_capture:
self.log_capture = LoggingCapture(self.config)
self.log_capture.inveigle()
self.context.log_capture = self.log_capture
def start_capture(self):
if self.config.stdout_capture:
# -- REPLACE ONLY: In non-capturing mode.
if not self.old_stdout:
self.old_stdout = sys.stdout
sys.stdout = self.stdout_capture
assert sys.stdout is self.stdout_capture
if self.config.stderr_capture:
# -- REPLACE ONLY: In non-capturing mode.
if not self.old_stderr:
self.old_stderr = sys.stderr
sys.stderr = self.stderr_capture
assert sys.stderr is self.stderr_capture
def stop_capture(self):
if self.config.stdout_capture:
# -- RESTORE ONLY: In capturing mode.
if self.old_stdout:
sys.stdout = self.old_stdout
self.old_stdout = None
assert sys.stdout is not self.stdout_capture
if self.config.stderr_capture:
# -- RESTORE ONLY: In capturing mode.
if self.old_stderr:
sys.stderr = self.old_stderr
self.old_stderr = None
assert sys.stderr is not self.stderr_capture
def teardown_capture(self):
if self.config.log_capture:
self.log_capture.abandon()
示例7: ModelRunner
# 需要导入模块: from behave.log_capture import LoggingCapture [as 别名]
# 或者: from behave.log_capture.LoggingCapture import abandon [as 别名]
#.........这里部分代码省略.........
if self.config.log_capture:
self.log_capture = LoggingCapture(self.config)
self.log_capture.inveigle()
self.context.log_capture = self.log_capture
def start_capture(self):
if self.config.stdout_capture:
# -- REPLACE ONLY: In non-capturing mode.
if not self.old_stdout:
self.old_stdout = sys.stdout
sys.stdout = self.stdout_capture
assert sys.stdout is self.stdout_capture
if self.config.stderr_capture:
# -- REPLACE ONLY: In non-capturing mode.
if not self.old_stderr:
self.old_stderr = sys.stderr
sys.stderr = self.stderr_capture
assert sys.stderr is self.stderr_capture
def stop_capture(self):
if self.config.stdout_capture:
# -- RESTORE ONLY: In capturing mode.
if self.old_stdout:
sys.stdout = self.old_stdout
self.old_stdout = None
assert sys.stdout is not self.stdout_capture
if self.config.stderr_capture:
# -- RESTORE ONLY: In capturing mode.
if self.old_stderr:
sys.stderr = self.old_stderr
self.old_stderr = None
assert sys.stderr is not self.stderr_capture
def teardown_capture(self):
if self.config.log_capture:
self.log_capture.abandon()
def run_model(self, features=None):
# pylint: disable=too-many-branches
if not self.context:
self.context = Context(self)
if self.step_registry is None:
self.step_registry = the_step_registry
if features is None:
features = self.features
# -- ENSURE: context.execute_steps() works in weird cases (hooks, ...)
context = self.context
self.hook_failures = 0
self.setup_capture()
self.run_hook("before_all", context)
run_feature = not self.aborted
failed_count = 0
undefined_steps_initial_size = len(self.undefined_steps)
for feature in features:
if run_feature:
try:
self.feature = feature
for formatter in self.formatters:
formatter.uri(feature.filename)
failed = feature.run(self)
if failed:
failed_count += 1
if self.config.stop or self.aborted:
# -- FAIL-EARLY: After first failure.
run_feature = False
except KeyboardInterrupt:
self.aborted = True
failed_count += 1
run_feature = False
# -- ALWAYS: Report run/not-run feature to reporters.
# REQUIRED-FOR: Summary to keep track of untested features.
for reporter in self.config.reporters:
reporter.feature(feature)
# -- AFTER-ALL:
if self.aborted:
print("\nABORTED: By user.")
for formatter in self.formatters:
formatter.close()
self.run_hook("after_all", self.context)
for reporter in self.config.reporters:
reporter.end()
failed = ((failed_count > 0) or self.aborted or (self.hook_failures > 0)
or (len(self.undefined_steps) > undefined_steps_initial_size))
return failed
def run(self):
"""
Implements the run method by running the model.
"""
self.context = Context(self)
return self.run_model()
示例8: CaptureController
# 需要导入模块: from behave.log_capture import LoggingCapture [as 别名]
# 或者: from behave.log_capture.LoggingCapture import abandon [as 别名]
class CaptureController(object):
"""Simplifies the lifecycle to capture output from various sources."""
def __init__(self, config):
self.config = config
self.stdout_capture = None
self.stderr_capture = None
self.log_capture = None
self.old_stdout = None
self.old_stderr = None
@property
def captured(self):
"""Provides access of the captured output data.
:return: Object that stores the captured output parts (as Captured).
"""
stdout = None
stderr = None
log_out = None
if self.config.stdout_capture and self.stdout_capture:
stdout = _text(self.stdout_capture.getvalue())
if self.config.stderr_capture and self.stderr_capture:
stderr = _text(self.stderr_capture.getvalue())
if self.config.log_capture and self.log_capture:
log_out = _text(self.log_capture.getvalue())
return Captured(stdout, stderr, log_out)
def setup_capture(self, context):
assert context is not None
if self.config.stdout_capture:
self.stdout_capture = StringIO()
context.stdout_capture = self.stdout_capture
if self.config.stderr_capture:
self.stderr_capture = StringIO()
context.stderr_capture = self.stderr_capture
if self.config.log_capture:
self.log_capture = LoggingCapture(self.config)
self.log_capture.inveigle()
context.log_capture = self.log_capture
def start_capture(self):
if self.config.stdout_capture:
# -- REPLACE ONLY: In non-capturing mode.
if not self.old_stdout:
self.old_stdout = sys.stdout
sys.stdout = self.stdout_capture
assert sys.stdout is self.stdout_capture
if self.config.stderr_capture:
# -- REPLACE ONLY: In non-capturing mode.
if not self.old_stderr:
self.old_stderr = sys.stderr
sys.stderr = self.stderr_capture
assert sys.stderr is self.stderr_capture
def stop_capture(self):
if self.config.stdout_capture:
# -- RESTORE ONLY: In capturing mode.
if self.old_stdout:
sys.stdout = self.old_stdout
self.old_stdout = None
assert sys.stdout is not self.stdout_capture
if self.config.stderr_capture:
# -- RESTORE ONLY: In capturing mode.
if self.old_stderr:
sys.stderr = self.old_stderr
self.old_stderr = None
assert sys.stderr is not self.stderr_capture
def teardown_capture(self):
if self.config.log_capture:
self.log_capture.abandon()
def make_capture_report(self):
"""Combine collected output and return as string."""
return self.captured.make_report()