Merge lp:~cjwatson/lazr.restful/py3-exception-scope into lp:lazr.restful

Proposed by Colin Watson
Status: Merged
Merged at revision: 249
Proposed branch: lp:~cjwatson/lazr.restful/py3-exception-scope
Merge into: lp:lazr.restful
Diff against target: 77 lines (+25/-18)
1 file modified
src/lazr/restful/tests/test_error.py (+25/-18)
To merge this branch: bzr merge lp:~cjwatson/lazr.restful/py3-exception-scope
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+387895@code.launchpad.net

Commit message

Handle exception scoping changes in Python 3.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restful/tests/test_error.py'
2--- src/lazr/restful/tests/test_error.py 2020-02-13 00:11:04 +0000
3+++ src/lazr/restful/tests/test_error.py 2020-07-22 22:52:42 +0000
4@@ -169,9 +169,10 @@
5 resource = self._setup_non_web_service_exception()
6 try:
7 resource()
8- except:
9- pass
10- self.assertTrue('raise exception_class()' in traceback.format_exc())
11+ except Exception:
12+ self.assertIn('raise exception_class()', traceback.format_exc())
13+ else:
14+ self.fail('No exception raised.')
15
16 def test_passing_bad_things_to_expose(self):
17 # The expose function only accepts instances of exceptions. It
18@@ -192,12 +193,16 @@
19 EntryAdapterUtility.forSchemaInterface(
20 IMyEntry, self.beta_request)
21 except Exception as e:
22- pass
23- self.assertTrue(isinstance(e, Exception))
24+ self.assertTrue(isinstance(e, Exception))
25
26- # The exception's message explains what went wrong.
27- self.assertTrue(str(e),
28- 'No IEntry adapter found for IMyEntry (web service version: beta).')
29+ # The exception's message explains what went wrong.
30+ self.assertTrue(str(e),
31+ 'No IEntry adapter found for IMyEntry '
32+ '(web service version: beta).')
33+ else:
34+ self.fail(
35+ 'EntryAdapterUtility.forSchemaInterface did not raise an '
36+ 'exception')
37
38 def test_missing_adapter_whence(self):
39 # The UnknownEntryAdapter exception has a "whence" attribute that
40@@ -221,12 +226,14 @@
41 resource = TestResource(broken, request)
42 try:
43 resource()
44- except:
45- pass
46- self.assertTrue(
47- "raise RuntimeError('something broke')" in traceback.format_exc())
48+ except Exception:
49+ self.assertIn(
50+ "raise RuntimeError('something broke')",
51+ traceback.format_exc())
52+ else:
53+ self.fail('No exception raised.')
54
55- def test_reporting_original_exception_with_no_trackeback(self):
56+ def test_reporting_original_exception_with_no_traceback(self):
57 # Sometimes an exception won't have an __traceback__ attribute. The
58 # re-raising should still work (bug 854695).
59 class TracebacklessException(Exception):
60@@ -241,12 +248,12 @@
61 'The resource should not have generated an AttributeError. '
62 'This is probably because something was expecting the '
63 'exception to have a __traceback__ attribute.')
64- except (MemoryError, KeyboardInterrupt, SystemExit):
65+ except MemoryError:
66 raise
67- except:
68- pass
69-
70- self.assertTrue("TracebacklessException" in traceback.format_exc())
71+ except Exception:
72+ self.assertIn("TracebacklessException", traceback.format_exc())
73+ else:
74+ self.fail('No exception raised.')
75
76
77 class FunctionalLayer:

Subscribers

People subscribed via source and target branches