From 6fda467597eda4e7ec0d0c4762f4b6f95b9e4b4a Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Fri, 26 Jan 2024 13:53:12 +0000 Subject: [PATCH] [FIX] tests: make sure screencasts dir exists before writing to it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this patch, running this command on an environment where the tour will fail, will create massive and useless logs: odoo --stop-after-init -i auth_totp --test-enable --test-tags /auth_totp This is because this method is a callback that can come in a different thread, creating a race condition. There's no problem on checking wether the directory exists before creating the file, and then safeguarding from the problem. @moduon MT-1075 closes odoo/odoo#151579 X-original-commit: 7aca8ae8728c66700c3afdca350e99ea78a63d88 Signed-off-by: Xavier Dollé (xdo) --- odoo/tests/common.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/odoo/tests/common.py b/odoo/tests/common.py index 03d3a1bf8c7..0dd1d5eb608 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -1343,12 +1343,15 @@ which leads to stray network requests and inconsistencies.""" def _handle_screencast_frame(self, sessionId, data, metadata): self._websocket_send('Page.screencastFrameAck', params={'sessionId': sessionId}) outfile = os.path.join(self.screencasts_frames_dir, 'frame_%05d.b64' % len(self.screencast_frames)) - with open(outfile, 'w') as f: - f.write(data) - self.screencast_frames.append({ - 'file_path': outfile, - 'timestamp': metadata.get('timestamp') - }) + try: + with open(outfile, 'w') as f: + f.write(data) + self.screencast_frames.append({ + 'file_path': outfile, + 'timestamp': metadata.get('timestamp') + }) + except FileNotFoundError: + self._logger.debug('Useless screencast frame skipped: %s', outfile) _TO_LEVEL = { 'debug': logging.DEBUG,