diff options
author | Ang Li <angli@google.com> | 2022-08-15 22:54:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-15 22:54:12 -0700 |
commit | 516b715f07ff4bc6f79513243d2e6c8546e4c907 (patch) | |
tree | ecf2c280c4b3f4a8654eb0f22858b9402d02fd9a | |
parent | 2da2ec36501a6e510d1b092d22fa03a71c40821f (diff) | |
download | mobly-516b715f07ff4bc6f79513243d2e6c8546e4c907.tar.gz |
Always create the `AndroidDevice` object specific log directory. (#848)
Create upon access if `log_path` doesn't exist
-rw-r--r-- | mobly/controllers/android_device.py | 6 | ||||
-rwxr-xr-x | tests/mobly/controllers/android_device_test.py | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/mobly/controllers/android_device.py b/mobly/controllers/android_device.py index 40b47a4..7d5064a 100644 --- a/mobly/controllers/android_device.py +++ b/mobly/controllers/android_device.py @@ -491,8 +491,8 @@ class AndroidDevice: def __init__(self, serial=''): self._serial = str(serial) # logging.log_path only exists when this is used in an Mobly test run. - self._log_path_base = getattr(logging, 'log_path', '/tmp/logs') - self._log_path = os.path.join(self._log_path_base, + _log_path_base = utils.abs_path(getattr(logging, 'log_path', '/tmp/logs')) + self._log_path = os.path.join(_log_path_base, 'AndroidDevice%s' % self._normalized_serial) self._debug_tag = self._serial self.log = AndroidDeviceLoggerAdapter(logging.getLogger(), @@ -621,6 +621,8 @@ class AndroidDevice: def log_path(self): """A string that is the path for all logs collected from this device. """ + if not os.path.exists(self._log_path): + utils.create_dir(self._log_path) return self._log_path @log_path.setter diff --git a/tests/mobly/controllers/android_device_test.py b/tests/mobly/controllers/android_device_test.py index a99f1e3..4aa5304 100755 --- a/tests/mobly/controllers/android_device_test.py +++ b/tests/mobly/controllers/android_device_test.py @@ -601,6 +601,7 @@ class AndroidDeviceTest(unittest.TestCase): self, sanitize_filename_mock, get_log_file_timestamp_mock, MockFastboot, MockAdbProxy): mock_serial = 1 + sanitize_filename_mock.return_value = '1' ad = android_device.AndroidDevice(serial=mock_serial) get_log_file_timestamp_mock.return_value = '07-22-2019_17-53-34-450' filename = ad.generate_filename('MagicLog') @@ -1098,8 +1099,7 @@ class AndroidDeviceTest(unittest.TestCase): """ expected_e = Exception('start failed.') MockSnippetClient.initialize = mock.Mock(side_effect=expected_e) - MockSnippetClient.stop = mock.Mock( - side_effect=Exception('stop failed.')) + MockSnippetClient.stop = mock.Mock(side_effect=Exception('stop failed.')) ad = android_device.AndroidDevice(serial='1') try: ad.load_snippet('snippet', MOCK_SNIPPET_PACKAGE_NAME) |