Skip to content

Commit

Permalink
Don't mutate BaseTestClass.record_data() argument. (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolverdude committed Dec 7, 2022
1 parent f788d41 commit 9238569
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions mobly/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ def record_data(self, content):
content: dict, the data to add to summary file.
"""
if 'timestamp' not in content:
content = content.copy()
content['timestamp'] = utils.get_current_epoch_time()
self.summary_writer.dump(content, records.TestSummaryEntryType.USER_DATA)

Expand Down
3 changes: 3 additions & 0 deletions tests/mobly/base_test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,7 @@ def logic(self, a, b):

def test_write_user_data(self):
content = {'a': 1}
original_content = content.copy()

class MockBaseTest(base_test.BaseTestClass):

Expand All @@ -2215,7 +2216,9 @@ def test_something(self):
continue
hit = True
self.assertEqual(c['a'], content['a'])
self.assertIn('timestamp', c)
self.assertIsNotNone(c['timestamp'])
self.assertEqual(content, original_content, 'Content arg was mutated.')
self.assertTrue(hit)

def test_record_controller_info(self):
Expand Down

0 comments on commit 9238569

Please sign in to comment.