diff options
author | John <puremonkey2001@yahoo.com.tw> | 2021-06-08 16:37:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-08 01:37:42 -0700 |
commit | cd253a4e05e717e0f4d5ea363bf6b60a2667135e (patch) | |
tree | e20f2d808e37e0408e5411ea0cb7f2a27179f4a4 /tests/mobly | |
parent | 113ac44c9a0cb83226ea4195954a3cb32228ad6b (diff) | |
download | mobly-cd253a4e05e717e0f4d5ea363bf6b60a2667135e.tar.gz |
Use `assertRaises` instead of catch and assert (#754)
Diffstat (limited to 'tests/mobly')
-rwxr-xr-x | tests/mobly/controllers/android_device_test.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/tests/mobly/controllers/android_device_test.py b/tests/mobly/controllers/android_device_test.py index 4d17083..b27d76f 100755 --- a/tests/mobly/controllers/android_device_test.py +++ b/tests/mobly/controllers/android_device_test.py @@ -1141,21 +1141,23 @@ class AndroidDeviceTest(unittest.TestCase): mock_serial = '1' ad = android_device.AndroidDevice(serial=mock_serial) self.assertEqual(ad.debug_tag, '1') - try: + with self.assertRaisesRegex( + android_device.DeviceError, + r'<AndroidDevice\|1> Something'): raise android_device.DeviceError(ad, 'Something') - except android_device.DeviceError as e: - self.assertEqual('<AndroidDevice|1> Something', str(e)) + # Verify that debug tag's setter updates the debug prefix correctly. ad.debug_tag = 'Mememe' - try: + with self.assertRaisesRegex( + android_device.DeviceError, + r'<AndroidDevice\|Mememe> Something'): raise android_device.DeviceError(ad, 'Something') - except android_device.DeviceError as e: - self.assertEqual('<AndroidDevice|Mememe> Something', str(e)) + # Verify that repr is changed correctly. - try: + with self.assertRaisesRegex( + Exception, + r'(<AndroidDevice\|Mememe>, \'Something\')'): raise Exception(ad, 'Something') - except Exception as e: - self.assertEqual("(<AndroidDevice|Mememe>, 'Something')", str(e)) @mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy', return_value=mock_android_device.MockAdbProxy('1')) |