diff options
author | Nathan Rossi <nathan@nathanrossi.com> | 2019-09-27 05:31:08 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-09-30 16:55:21 +0100 |
commit | 02a334c98fef6a8af9ee3dcd29815dbe6d145d3c (patch) | |
tree | 336b39e673db81418f9ab00f7e82d52416a05e98 /meta | |
parent | e25ee9fe28353b9c53d445a2ff63fc896f2c74f5 (diff) | |
download | poky-02a334c98fef6a8af9ee3dcd29815dbe6d145d3c.tar.gz |
oeqa/core/utils/concurrencytest.py: Handle exceptions and details
Handle the streaming of exception content with details data. The
testtools package allows both 'err' and 'details' kwargs but can only
pass one of them to the parent.
To handle the passing of exception traceback and details data at the
same time, encode the traceback into the details object and remove the
'err' arg from the add* result call. This encodes the traceback similar
to how 'err' is handled without any details object. Decoding is already
done by testtools when the traceback is encoded in the details object.
(From OE-Core rev: 3613451825b251784b7673d89db465b9782c3a31)
Signed-off-by: Nathan Rossi <nathan@nathanrossi.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/core/utils/concurrencytest.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/meta/lib/oeqa/core/utils/concurrencytest.py b/meta/lib/oeqa/core/utils/concurrencytest.py index 6293cf94ec..0f7b3dcc11 100644 --- a/meta/lib/oeqa/core/utils/concurrencytest.py +++ b/meta/lib/oeqa/core/utils/concurrencytest.py | |||
@@ -78,29 +78,29 @@ class ProxyTestResult: | |||
78 | def __init__(self, target): | 78 | def __init__(self, target): |
79 | self.result = target | 79 | self.result = target |
80 | 80 | ||
81 | def _addResult(self, method, test, *args, **kwargs): | 81 | def _addResult(self, method, test, *args, exception = False, **kwargs): |
82 | return method(test, *args, **kwargs) | 82 | return method(test, *args, **kwargs) |
83 | 83 | ||
84 | def addError(self, test, *args, **kwargs): | 84 | def addError(self, test, err = None, **kwargs): |
85 | self._addResult(self.result.addError, test, *args, **kwargs) | 85 | self._addResult(self.result.addError, test, err, exception = True, **kwargs) |
86 | 86 | ||
87 | def addFailure(self, test, *args, **kwargs): | 87 | def addFailure(self, test, err = None, **kwargs): |
88 | self._addResult(self.result.addFailure, test, *args, **kwargs) | 88 | self._addResult(self.result.addFailure, test, err, exception = True, **kwargs) |
89 | 89 | ||
90 | def addSuccess(self, test, *args, **kwargs): | 90 | def addSuccess(self, test, **kwargs): |
91 | self._addResult(self.result.addSuccess, test, *args, **kwargs) | 91 | self._addResult(self.result.addSuccess, test, **kwargs) |
92 | 92 | ||
93 | def addExpectedFailure(self, test, *args, **kwargs): | 93 | def addExpectedFailure(self, test, err = None, **kwargs): |
94 | self._addResult(self.result.addExpectedFailure, test, *args, **kwargs) | 94 | self._addResult(self.result.addExpectedFailure, test, err, exception = True, **kwargs) |
95 | 95 | ||
96 | def addUnexpectedSuccess(self, test, *args, **kwargs): | 96 | def addUnexpectedSuccess(self, test, **kwargs): |
97 | self._addResult(self.result.addUnexpectedSuccess, test, *args, **kwargs) | 97 | self._addResult(self.result.addUnexpectedSuccess, test, **kwargs) |
98 | 98 | ||
99 | def __getattr__(self, attr): | 99 | def __getattr__(self, attr): |
100 | return getattr(self.result, attr) | 100 | return getattr(self.result, attr) |
101 | 101 | ||
102 | class ExtraResultsDecoderTestResult(ProxyTestResult): | 102 | class ExtraResultsDecoderTestResult(ProxyTestResult): |
103 | def _addResult(self, method, test, *args, **kwargs): | 103 | def _addResult(self, method, test, *args, exception = False, **kwargs): |
104 | if "details" in kwargs and "extraresults" in kwargs["details"]: | 104 | if "details" in kwargs and "extraresults" in kwargs["details"]: |
105 | if isinstance(kwargs["details"]["extraresults"], Content): | 105 | if isinstance(kwargs["details"]["extraresults"], Content): |
106 | kwargs = kwargs.copy() | 106 | kwargs = kwargs.copy() |
@@ -114,7 +114,7 @@ class ExtraResultsDecoderTestResult(ProxyTestResult): | |||
114 | return method(test, *args, **kwargs) | 114 | return method(test, *args, **kwargs) |
115 | 115 | ||
116 | class ExtraResultsEncoderTestResult(ProxyTestResult): | 116 | class ExtraResultsEncoderTestResult(ProxyTestResult): |
117 | def _addResult(self, method, test, *args, **kwargs): | 117 | def _addResult(self, method, test, *args, exception = False, **kwargs): |
118 | if hasattr(test, "extraresults"): | 118 | if hasattr(test, "extraresults"): |
119 | extras = lambda : [json.dumps(test.extraresults).encode()] | 119 | extras = lambda : [json.dumps(test.extraresults).encode()] |
120 | kwargs = kwargs.copy() | 120 | kwargs = kwargs.copy() |
@@ -123,6 +123,11 @@ class ExtraResultsEncoderTestResult(ProxyTestResult): | |||
123 | else: | 123 | else: |
124 | kwargs["details"] = kwargs["details"].copy() | 124 | kwargs["details"] = kwargs["details"].copy() |
125 | kwargs["details"]["extraresults"] = Content(ContentType("application", "json", {'charset': 'utf8'}), extras) | 125 | kwargs["details"]["extraresults"] = Content(ContentType("application", "json", {'charset': 'utf8'}), extras) |
126 | # if using details, need to encode any exceptions into the details obj, | ||
127 | # testtools does not handle "err" and "details" together. | ||
128 | if "details" in kwargs and exception and (len(args) >= 1 and args[0] is not None): | ||
129 | kwargs["details"]["traceback"] = testtools.content.TracebackContent(args[0], test) | ||
130 | args = [] | ||
126 | return method(test, *args, **kwargs) | 131 | return method(test, *args, **kwargs) |
127 | 132 | ||
128 | # | 133 | # |