Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Test result when the case failed."""
_tag = "failure"
def __eq__(self, other):
return super(Failure, self).__eq__(other)
class Error(Result):
"""Test result when the case has errors during execution."""
_tag = "error"
def __eq__(self, other):
return super(Error, self).__eq__(other)
POSSIBLE_RESULTS = {Failure, Error, Skipped}
class TestCase(Element, PropertiesFunc):
"""Object to store a testcase and its result.
Attributes:
name: case name
classname: the parent class of the case
time: how much time is consumed by the test
Properties:
result: Failure, Skipped, or Error
system_out: stdout
system_err: stderr
"""
"""Test result when the case failed."""
_tag = "failure"
def __eq__(self, other):
return super(Failure, self).__eq__(other)
class Error(Result):
"""Test result when the case has errors during execution."""
_tag = "error"
def __eq__(self, other):
return super(Error, self).__eq__(other)
POSSIBLE_RESULTS = {Failure, Error, Skipped}
class TestCase(Element):
"""Object to store a testcase and its result.
Attributes:
name: case name
classname: the parent class of the case
time: how much time is consumed by the test
Properties:
result: Failure, Skipped, or Error
system_out: stdout
system_err: stderr
"""
def result(self, value):
# First remove all existing results
for res in POSSIBLE_RESULTS:
result = self.child(res)
if result is not None:
self.remove(result)
# Then add current result
if isinstance(value, Skipped) or isinstance(value, Failure) or isinstance(value, Error):
self.append(value)
def __eq__(self, other):
return super(Skipped, self).__eq__(other)
def update_statistics(self):
"""Updates test count and test time."""
tests = errors = failures = skipped = 0
time = 0
for case in self:
tests += 1
if isinstance(case.result, Failure):
failures += 1
elif isinstance(case.result, Error):
errors += 1
elif isinstance(case.result, Skipped):
skipped += 1
if case.time is not None:
time += case.time
self.tests = tests
self.errors = errors
self.failures = failures
self.skipped = skipped
self.time = time
def __eq__(self, other):
return super(Skipped, self).__eq__(other)