Skip to content

Commit

Permalink
Fix flaky unit test gui
Browse files Browse the repository at this point in the history
When running some of the gui unit tests in parallell, they would share storage. This was very prevalent for the test unit_tests/gui/test_main_window.py::test_that_gui_plotter_works_when_no_data, where the PlotApi would return data from the other tests (which running esmda). This is fixed in this PR by mocking the return value from PlotApi.
  • Loading branch information
jonathan-eq committed Feb 2, 2024
1 parent 36d0b32 commit ce32436
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions tests/unit_tests/gui/test_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
CaseSelectCheckButton,
CaseSelectionWidget,
)
from ert.gui.tools.plot.plot_window import PlotApi
from ert.gui.tools.plot.plot_window import PlotWindow
from ert.run_models import SingleTestRun
from ert.services import StorageService
Expand Down Expand Up @@ -765,31 +766,27 @@ def handle_error_dialog(run_dialog):


@pytest.mark.usefixtures("use_tmpdir")
def test_that_gui_plotter_works_when_no_data(qtbot, storage):
def test_that_gui_plotter_works_when_no_data(qtbot, storage, monkeypatch):
monkeypatch.setattr(PlotApi, "_get_all_cases", lambda _: [])
config_file = "minimal_config.ert"
with open(config_file, "w", encoding="utf-8") as f:
f.write("NUM_REALIZATIONS 1")
args_mock = Mock()
args_mock.config = config_file

ert_config = ErtConfig.from_file(config_file)
enkf_main = EnKFMain(ert_config)
with StorageService.init_service(
ert_config=config_file,
project=os.path.abspath(ert_config.ens_path),
):
gui = _setup_main_window(enkf_main, args_mock, GUILogHandler())
gui.notifier.set_storage(storage)
qtbot.addWidget(gui)
gui.tools["Create plot"].trigger()
gui = _setup_main_window(enkf_main, args_mock, GUILogHandler())
gui.notifier.set_storage(storage)
qtbot.addWidget(gui)
gui.tools["Create plot"].trigger()

plot_window = wait_for_child(gui, qtbot, PlotWindow)
case_selection = get_child(plot_window, CaseSelectionWidget)
assert isinstance(case_selection, CaseSelectionWidget)
toggle_buttons = get_children(
case_selection, CaseSelectCheckButton, "case_selector"
)
assert len(toggle_buttons) == 0
plot_window = wait_for_child(gui, qtbot, PlotWindow)
case_selection = get_child(plot_window, CaseSelectionWidget)
assert isinstance(case_selection, CaseSelectionWidget)
toggle_buttons = get_children(
case_selection, CaseSelectCheckButton, "case_selector"
)
assert len(toggle_buttons) == 0


@pytest.mark.usefixtures("copy_poly_case")
Expand Down

0 comments on commit ce32436

Please sign in to comment.