Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _fill_sample(self, report, call, item, status):
filename, lineno, _ = report.location
if self._sample is None:
self._sample = Sample()
self._sample.test_case = item.name
self._sample.test_suite = item.module.__name__
self._sample.start_time = call.start
self._sample.extras = {"filename": filename, "lineno": lineno}
self._sample.status = status
self._sample.duration = time.time() - self._sample.start_time
if call.excinfo is not None:
self._sample.error_msg = call.excinfo.exconly().strip()
self._sample.error_trace = "\n".join(traceback.format_tb(call.excinfo.tb)).strip()
if call.excinfo.errisinstance(AssertionError):
self._sample.add_assertion(call.excinfo.exconly())
self._sample.set_assertion_failed(call.excinfo.exconly(), str(call.excinfo.value),
str(call.excinfo.getrepr(style="native")))
def end_test(self, name, attrs):
# TODO: include keywords as subsamples
sample = Sample()
sample.test_case = name
sample.test_suite = self._current_suite
sample.start_time = time.mktime(datetime.strptime(attrs['starttime'], '%Y%m%d %H:%M:%S.%f').timetuple())
sample.duration = float(attrs['elapsedtime']) / 1000.0
if attrs['status'] == 'PASS':
sample.status = 'PASSED'
else:
sample.status = 'FAILED'
message = attrs['message']
if '\n' in message:
lines = message.split('\n')
sample.error_msg = lines[0]
sample.error_trace = message
else:
sample.error_msg = message
self._report_sample(sample)