From f1c87d1bd2a693ec09f52b89878ab4a45ae37d09 Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Wed, 2 Apr 2025 21:38:05 +0200 Subject: [PATCH] Fix: Multi-window UI tests can produce inconsistent results After creating a new scene in a separate window when performing UI tests, the respective view layer for the window may not be updated immediately in the event loop. Previously, this was mitigated with a single `yield` statement that would delay processing by a single tick. To fix this issue, this commit adds the capability to yield for a specific `timedelta` and waits this amount of time for the two affected tests. Pull Request: https://projects.blender.org/blender/blender/pulls/136012 --- tests/python/ui_simulate/modules/easy_keys.py | 3 +++ tests/python/ui_simulate/test_undo.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/python/ui_simulate/modules/easy_keys.py b/tests/python/ui_simulate/modules/easy_keys.py index d21a3972aae..cf155ed69fe 100644 --- a/tests/python/ui_simulate/modules/easy_keys.py +++ b/tests/python/ui_simulate/modules/easy_keys.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: GPL-2.0-or-later +import datetime import string import bpy event_types = tuple( @@ -341,6 +342,8 @@ def run( if isinstance(val, EventGenerate) or val is None: return 0.0 + elif isinstance(val, datetime.timedelta): + return val.total_seconds() elif val is Ellipsis: if on_exit is not None: on_exit() diff --git a/tests/python/ui_simulate/test_undo.py b/tests/python/ui_simulate/test_undo.py index 186f56ea415..633a5c8020e 100644 --- a/tests/python/ui_simulate/test_undo.py +++ b/tests/python/ui_simulate/test_undo.py @@ -5,6 +5,7 @@ """ This file does not run anything, it's methods are accessed for tests by: ``run.py``. """ +import datetime # FIXME: Since 2.8 or so, there is a problem with simulated events # where a popup needs the main-loop to cycle once before new events @@ -653,7 +654,10 @@ def view3d_multi_mode_multi_window(): yield from _call_menu(e_b, "New Scene") yield e_b.ret() if _MENU_CONFIRM_HACK: - yield + # We wait for a brief period of time after confirming to ensure that each main window has a different view layer + yield datetime.timedelta(seconds=1 / 60) + + t.assertNotEqual(window_a.view_layer, window_b.view_layer, "Windows should have different view layers") for e in (e_a, e_b): pos_v3d = _cursor_position_from_spacetype(e.window, 'VIEW_3D') @@ -809,7 +813,10 @@ def view3d_edit_mode_multi_window(): yield from _call_menu(e_b, "New Scene") yield e_b.ret() if _MENU_CONFIRM_HACK: - yield + # We wait for a brief period of time after confirming to ensure that each main window has a different view layer + yield datetime.timedelta(seconds=1 / 60) + + t.assertNotEqual(window_a.view_layer, window_b.view_layer, "Windows should have different view layers") for e in (e_a, e_b): pos_v3d = _cursor_position_from_spacetype(e.window, 'VIEW_3D')