Skip to content

Commit

Permalink
Minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
xpconanfan committed Oct 21, 2019
1 parent 7552a2a commit b206a97
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions mobly/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def __init__(self, configs):
# Set params.
self.root_output_path = configs.log_path
self.log_path = os.path.join(self.root_output_path, class_identifier)
utils.create_dir(self.log_path)
# Deprecated, use 'testbed_name'
self.test_bed_name = configs.test_bed_name
self.testbed_name = configs.testbed_name
Expand Down
17 changes: 10 additions & 7 deletions mobly/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ class TestRunner(object):
self.results: The test result object used to record the results of
this test run.
"""

class _TestRunInfo(object):
"""Identifies one test class to run, which tests to run, and config to
run it with.
"""

def __init__(self,
config,
test_class,
Expand Down Expand Up @@ -223,8 +225,9 @@ def __init__(self, log_dir, testbed_name):
def _update_log_path(self):
"""Updates the logging values with the current timestamp."""
self._start_time = logger.get_log_file_timestamp()
self._log_path = os.path.join(self._log_dir, self._testbed_name,
self._start_time)
self._root_output_path = os.path.join(self._log_dir,
self._testbed_name,
self._start_time)

@contextlib.contextmanager
def mobly_logger(self, alias='latest'):
Expand All @@ -239,11 +242,11 @@ def mobly_logger(self, alias='latest'):
The host file path where the logs for the test run are stored.
"""
self._update_log_path()
logger.setup_test_logger(self._log_path,
logger.setup_test_logger(self._root_output_path,
self._testbed_name,
alias=alias)
try:
yield self._log_path
yield self._root_output_path
finally:
logger.kill_test_logger(logging.getLogger())

Expand Down Expand Up @@ -318,15 +321,15 @@ def run(self):

# Ensure the log path exists. Necessary if `run` is used outside of the
# `mobly_logger` context.
utils.create_dir(self._log_path)
utils.create_dir(self._root_output_path)

summary_writer = records.TestSummaryWriter(
os.path.join(self._log_path, records.OUTPUT_FILE_SUMMARY))
os.path.join(self._root_output_path, records.OUTPUT_FILE_SUMMARY))
try:
for test_run_info in self._test_run_infos:
# Set up the test-specific config
test_config = test_run_info.config.copy()
test_config.log_path = self._log_path
test_config.log_path = self._root_output_path
test_config.summary_writer = summary_writer
test_config.test_class_name_suffix = test_run_info.test_class_name_suffix
try:
Expand Down
1 change: 1 addition & 0 deletions tests/mobly/base_test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_func(self):
self.assertEqual(path_checker.root_output_path, self.tmp_dir)
expected_log_path = os.path.join(self.tmp_dir, 'MockBaseTest')
self.assertEqual(path_checker.log_path, expected_log_path)
self.assertTrue(os.path.exists(path_checker.log_path))

def test_current_test_name(self):
class MockBaseTest(base_test.BaseTestClass):
Expand Down

0 comments on commit b206a97

Please sign in to comment.