Skip to content

Commit

Permalink
Fix flaky unit test gui plotapi sharing storage
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 commit by mocking the return value from PlotApi.
  • Loading branch information
jonathan-eq committed Feb 2, 2024
1 parent 36d0b32 commit 9ca4876
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions tests/unit_tests/gui/test_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
CaseSelectCheckButton,
CaseSelectionWidget,
)
from ert.gui.tools.plot.plot_window import PlotWindow
from ert.gui.tools.plot.plot_window import PlotApi, PlotWindow
from ert.run_models import SingleTestRun
from ert.services import StorageService
from ert.shared.plugins.plugin_manager import ErtPluginManager
Expand Down Expand Up @@ -765,13 +765,13 @@ 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(
Expand All @@ -782,7 +782,6 @@ def test_that_gui_plotter_works_when_no_data(qtbot, storage):
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)
Expand Down

0 comments on commit 9ca4876

Please sign in to comment.