summaryrefslogtreecommitdiff
path: root/buildscripts/resmokelib/testing/report.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/resmokelib/testing/report.py')
-rw-r--r--buildscripts/resmokelib/testing/report.py131
1 files changed, 43 insertions, 88 deletions
diff --git a/buildscripts/resmokelib/testing/report.py b/buildscripts/resmokelib/testing/report.py
index f13cfdc9a84..c968449c8a2 100644
--- a/buildscripts/resmokelib/testing/report.py
+++ b/buildscripts/resmokelib/testing/report.py
@@ -1,6 +1,6 @@
-"""
-Extension to the unittest.TestResult to support additional test status
-and timing information for the report.json file.
+"""Extension to the unittest.TestResult.
+
+This is used to support additional test status and timing information for the report.json file.
"""
from __future__ import absolute_import
@@ -14,15 +14,12 @@ from .. import config as _config
from .. import logging
-class TestReport(unittest.TestResult):
- """
- Records test status and timing information.
- """
+# pylint: disable=attribute-defined-outside-init
+class TestReport(unittest.TestResult): # pylint: disable=too-many-instance-attributes
+ """Record test status and timing information."""
def __init__(self, job_logger, suite_options):
- """
- Initializes the TestReport with the buildlogger configuration.
- """
+ """Initialize the TestReport with the buildlogger configuration."""
unittest.TestResult.__init__(self)
@@ -35,8 +32,7 @@ class TestReport(unittest.TestResult):
@classmethod
def combine(cls, *reports):
- """
- Merges the results from multiple TestReport instances into one.
+ """Merge the results from multiple TestReport instances into one.
If the same test is present in multiple reports, then one that
failed or errored is more preferred over one that succeeded.
@@ -54,7 +50,7 @@ class TestReport(unittest.TestResult):
if not isinstance(report, TestReport):
raise TypeError("reports must be a list of TestReport instances")
- with report._lock:
+ with report._lock: # pylint: disable=protected-access
for test_info in report.test_infos:
# If the user triggers a KeyboardInterrupt exception while a test is running,
# then it is possible for 'test_info' to be modified by a job thread later on.
@@ -93,10 +89,8 @@ class TestReport(unittest.TestResult):
return combined_report
- def startTest(self, test, dynamic=False):
- """
- Called immediately before 'test' is run.
- """
+ def startTest(self, test, dynamic=False): # pylint: disable=invalid-name,arguments-differ
+ """Call before 'test' is run."""
unittest.TestResult.startTest(self, test)
@@ -119,15 +113,13 @@ class TestReport(unittest.TestResult):
test.override_logger(test_logger)
- def stopTest(self, test):
- """
- Called immediately after 'test' has run.
- """
+ def stopTest(self, test): # pylint: disable=invalid-name
+ """Call after 'test' has run."""
unittest.TestResult.stopTest(self, test)
with self._lock:
- test_info = self._find_test_info(test)
+ test_info = self.find_test_info(test)
test_info.end_time = time.time()
time_taken = test_info.end_time - test_info.start_time
@@ -143,11 +135,8 @@ class TestReport(unittest.TestResult):
# Restore the original logger for the test.
test.reset_logger()
- def addError(self, test, err):
- """
- Called when a non-failureException was raised during the
- execution of 'test'.
- """
+ def addError(self, test, err): # pylint: disable=invalid-name
+ """Call when a non-failureException was raised during the execution of 'test'."""
unittest.TestResult.addError(self, test, err)
@@ -155,18 +144,16 @@ class TestReport(unittest.TestResult):
self.num_errored += 1
# We don't distinguish between test failures and Python errors in Evergreen.
- test_info = self._find_test_info(test)
+ test_info = self.find_test_info(test)
test_info.status = "error"
test_info.evergreen_status = "fail"
test_info.return_code = test.return_code
- def setError(self, test):
- """
- Used to change the outcome of an existing test to an error.
- """
+ def setError(self, test): # pylint: disable=invalid-name
+ """Change the outcome of an existing test to an error."""
with self._lock:
- test_info = self._find_test_info(test)
+ test_info = self.find_test_info(test)
if test_info.end_time is None:
raise ValueError("stopTest was not called on %s" % (test.basename()))
@@ -181,18 +168,15 @@ class TestReport(unittest.TestResult):
self.num_errored = len(self.get_errored())
self.num_interrupted = len(self.get_interrupted())
- def addFailure(self, test, err):
- """
- Called when a failureException was raised during the execution
- of 'test'.
- """
+ def addFailure(self, test, err): # pylint: disable=invalid-name
+ """Call when a failureException was raised during the execution of 'test'."""
unittest.TestResult.addFailure(self, test, err)
with self._lock:
self.num_failed += 1
- test_info = self._find_test_info(test)
+ test_info = self.find_test_info(test)
test_info.status = "fail"
if test_info.dynamic:
# Dynamic tests are used for data consistency checks, so the failures are never
@@ -202,13 +186,11 @@ class TestReport(unittest.TestResult):
test_info.evergreen_status = self.suite_options.report_failure_status
test_info.return_code = test.return_code
- def setFailure(self, test, return_code=1):
- """
- Used to change the outcome of an existing test to a failure.
- """
+ def setFailure(self, test, return_code=1): # pylint: disable=invalid-name
+ """Change the outcome of an existing test to a failure."""
with self._lock:
- test_info = self._find_test_info(test)
+ test_info = self.find_test_info(test)
if test_info.end_time is None:
raise ValueError("stopTest was not called on %s" % (test.basename()))
@@ -227,68 +209,51 @@ class TestReport(unittest.TestResult):
self.num_errored = len(self.get_errored())
self.num_interrupted = len(self.get_interrupted())
- def addSuccess(self, test):
- """
- Called when 'test' executed successfully.
- """
+ def addSuccess(self, test): # pylint: disable=invalid-name
+ """Call when 'test' executed successfully."""
unittest.TestResult.addSuccess(self, test)
with self._lock:
self.num_succeeded += 1
- test_info = self._find_test_info(test)
+ test_info = self.find_test_info(test)
test_info.status = "pass"
test_info.evergreen_status = "pass"
test_info.return_code = test.return_code
- def wasSuccessful(self):
- """
- Returns true if all tests executed successfully.
- """
+ def wasSuccessful(self): # pylint: disable=invalid-name
+ """Return true if all tests executed successfully."""
with self._lock:
return self.num_failed == self.num_errored == self.num_interrupted == 0
def get_successful(self):
- """
- Returns the status and timing information of the tests that
- executed successfully.
- """
+ """Return the status and timing information of the tests that executed successfully."""
with self._lock:
return [test_info for test_info in self.test_infos if test_info.status == "pass"]
def get_failed(self):
- """
- Returns the status and timing information of the tests that
- raised a failureException during their execution.
- """
+ """Return the status and timing information of tests that raised a failureException."""
with self._lock:
return [test_info for test_info in self.test_infos if test_info.status == "fail"]
def get_errored(self):
- """
- Returns the status and timing information of the tests that
- raised a non-failureException during their execution.
- """
+ """Return the status and timing information of tests that raised a non-failureException."""
with self._lock:
return [test_info for test_info in self.test_infos if test_info.status == "error"]
def get_interrupted(self):
- """
- Returns the status and timing information of the tests that had
- their execution interrupted.
- """
+ """Return the status and timing information of tests that were execution interrupted."""
with self._lock:
return [test_info for test_info in self.test_infos if test_info.status == "timeout"]
def as_dict(self):
- """
- Return the test result information as a dictionary.
+ """Return the test result information as a dictionary.
Used to create the report.json file.
"""
@@ -318,8 +283,7 @@ class TestReport(unittest.TestResult):
@classmethod
def from_dict(cls, report_dict):
- """
- Returns the test report instance copied from a dict (generated in as_dict).
+ """Return the test report instance copied from a dict (generated in as_dict).
Used when combining reports instances.
"""
@@ -349,9 +313,7 @@ class TestReport(unittest.TestResult):
return report
def reset(self):
- """
- Resets the test report back to its initial state.
- """
+ """Reset the test report back to its initial state."""
with self._lock:
self.test_infos = []
@@ -362,11 +324,8 @@ class TestReport(unittest.TestResult):
self.num_errored = 0
self.num_interrupted = 0
- def _find_test_info(self, test):
- """
- Returns the status and timing information associated with
- 'test'.
- """
+ def find_test_info(self, test):
+ """Return the status and timing information associated with 'test'."""
test_id = test.id()
@@ -379,15 +338,11 @@ class TestReport(unittest.TestResult):
raise ValueError("Details for %s not found in the report" % (test.basename()))
-class _TestInfo(object):
- """
- Holder for the test status and timing information.
- """
+class _TestInfo(object): # pylint: disable=too-many-instance-attributes
+ """Holder for the test status and timing information."""
def __init__(self, test_id, dynamic):
- """
- Initializes the _TestInfo instance.
- """
+ """Initialize the _TestInfo instance."""
self.test_id = test_id
self.dynamic = dynamic