Show More
@@ -173,6 +173,13 b' except Exception as e:' | |||||
173 | raise KeyError('uh') |
|
173 | raise KeyError('uh') | |
174 | """ |
|
174 | """ | |
175 |
|
175 | |||
|
176 | SUPPRESS_CHAINING_CODE = """ | |||
|
177 | try: | |||
|
178 | 1/0 | |||
|
179 | except Exception: | |||
|
180 | raise ValueError("Yikes") from None | |||
|
181 | """ | |||
|
182 | ||||
176 | def test_direct_cause_error(self): |
|
183 | def test_direct_cause_error(self): | |
177 | if PY3: |
|
184 | if PY3: | |
178 | with tt.AssertPrints(["KeyError", "NameError", "direct cause"]): |
|
185 | with tt.AssertPrints(["KeyError", "NameError", "direct cause"]): | |
@@ -182,3 +189,9 b' except Exception as e:' | |||||
182 | if PY3: |
|
189 | if PY3: | |
183 | with tt.AssertPrints(["KeyError", "NameError", "During handling"]): |
|
190 | with tt.AssertPrints(["KeyError", "NameError", "During handling"]): | |
184 | ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE) |
|
191 | ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE) | |
|
192 | ||||
|
193 | def test_suppress_exception_chaining(self): | |||
|
194 | if PY3: | |||
|
195 | with tt.AssertNotPrints("ZeroDivisionError"), \ | |||
|
196 | tt.AssertPrints("ValueError", suppress=False): | |||
|
197 | ip.run_cell(self.SUPPRESS_CHAINING_CODE) |
@@ -985,6 +985,8 b' class VerboseTB(TBTools):' | |||||
985 | cause = getattr(exception_value, '__cause__', None) |
|
985 | cause = getattr(exception_value, '__cause__', None) | |
986 | if cause: |
|
986 | if cause: | |
987 | return cause |
|
987 | return cause | |
|
988 | if getattr(exception_value, '__suppress_context__', False): | |||
|
989 | return None | |||
988 | return getattr(exception_value, '__context__', None) |
|
990 | return getattr(exception_value, '__context__', None) | |
989 |
|
991 | |||
990 | chained_evalue = get_chained_exception(evalue) |
|
992 | chained_evalue = get_chained_exception(evalue) |
General Comments 0
You need to be logged in to leave comments.
Login now