~canonical-platform-qa/autopilot/xlib-version

« back to all changes in this revision

Viewing changes to autopilot/testresult.py

Code cleanup for the autopilot.testresult module.

Approved by PS Jenkins bot, Christopher Lee.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        if get_log_verbose():
44
44
            logging.getLogger().log(level, message)
45
45
 
46
 
    def _log_details(self, level, details):
 
46
    def _log_details(self, level, test):
47
47
        """Log the relavent test details."""
48
 
 
49
 
        for detail in details:
50
 
            # Skip the test-log as it was logged while the test executed
51
 
            if detail == "test-log":
52
 
                continue
53
 
            detail_content = details[detail]
54
 
            if detail_content.content_type.type == "text":
55
 
                text = "%s: {{{\n%s}}}" % (detail, detail_content.as_text())
56
 
            else:
57
 
                text = "Binary attachment: \"%s\" (%s)" % (
58
 
                    detail,
59
 
                    detail_content.content_type
60
 
                )
61
 
            self._log(level, text)
 
48
        if hasattr(test, "getDetails"):
 
49
            details = test.getDetails()
 
50
            for detail in details:
 
51
                # Skip the test-log as it was logged while the test executed
 
52
                if detail == "test-log":
 
53
                    continue
 
54
                detail_content = details[detail]
 
55
                if detail_content.content_type.type == "text":
 
56
                    text = "%s: {{{\n%s}}}" % (
 
57
                        detail,
 
58
                        detail_content.as_text()
 
59
                    )
 
60
                else:
 
61
                    text = "Binary attachment: \"%s\" (%s)" % (
 
62
                        detail,
 
63
                        detail_content.content_type
 
64
                    )
 
65
                self._log(level, text)
62
66
 
63
67
    def addSuccess(self, test, details=None):
64
68
        self._log(logging.INFO, "OK: %s" % (test.id()))
65
 
        return super(LoggedTestResultDecorator, self).addSuccess(test, details)
 
69
        return super().addSuccess(test, details)
66
70
 
67
71
    def addError(self, test, err=None, details=None):
68
72
        self._log(logging.ERROR, "ERROR: %s" % (test.id()))
69
 
        if hasattr(test, "getDetails"):
70
 
            self._log_details(logging.ERROR, test.getDetails())
71
 
        return super(type(self), self).addError(test, err, details)
 
73
        self._log_details(logging.ERROR, test)
 
74
        return super().addError(test, err, details)
72
75
 
73
76
    def addFailure(self, test, err=None, details=None):
74
77
        """Called for a test which failed an assert."""
75
78
        self._log(logging.ERROR, "FAIL: %s" % (test.id()))
76
 
        if hasattr(test, "getDetails"):
77
 
            self._log_details(logging.ERROR, test.getDetails())
78
 
        return super(type(self), self).addFailure(test, err, details)
 
79
        self._log_details(logging.ERROR, test)
 
80
        return super().addFailure(test, err, details)
79
81
 
80
82
    def addSkip(self, test, reason=None, details=None):
81
83
        self._log(logging.INFO, "SKIP: %s" % test.id())
83
85
 
84
86
    def addUnexpectedSuccess(self, test, details=None):
85
87
        self._log(logging.ERROR, "UNEXPECTED SUCCESS: %s" % test.id())
86
 
        if hasattr(test, "getDetails"):
87
 
            self._log_details(logging.ERROR, test.getDetails())
 
88
        self._log_details(logging.ERROR, test)
88
89
        return super().addUnexpectedSuccess(test, details)
89
90
 
90
91
    def addExpectedFailure(self, test, err=None, details=None):