From 4de22d3ef9e473106705dabf4625c88b3402a450 Mon Sep 17 00:00:00 2001 From: Jonathan Karlsen Date: Wed, 20 Nov 2024 15:07:00 +0100 Subject: [PATCH] Fix tests --- .../test_forward_model_step.py | 2 +- .../forward_model_runner/test_job_dispatch.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/ert/unit_tests/forward_model_runner/test_forward_model_step.py b/tests/ert/unit_tests/forward_model_runner/test_forward_model_step.py index c6a29db3503..c10a82ee56a 100644 --- a/tests/ert/unit_tests/forward_model_runner/test_forward_model_step.py +++ b/tests/ert/unit_tests/forward_model_runner/test_forward_model_step.py @@ -207,7 +207,7 @@ def mocked_process(pid): return MockedProcess(123) monkeypatch.setattr(forward_model_step, "Process", mocked_process) - (_, _, oom_score) = _get_processtree_data(MockedProcess(123)) + (_, _, oom_score) = _get_processtree_data(123) assert oom_score == 456 diff --git a/tests/ert/unit_tests/forward_model_runner/test_job_dispatch.py b/tests/ert/unit_tests/forward_model_runner/test_job_dispatch.py index e59fadb4af7..44dcb8177b7 100644 --- a/tests/ert/unit_tests/forward_model_runner/test_job_dispatch.py +++ b/tests/ert/unit_tests/forward_model_runner/test_job_dispatch.py @@ -10,7 +10,6 @@ import sys from subprocess import Popen from textwrap import dedent -from unittest.mock import mock_open import pandas as pd import psutil @@ -357,16 +356,21 @@ async def test_job_dispatch_kills_itself_after_unsuccessful_job( ): host = "localhost" port = unused_tcp_port - jobs_json = json.dumps( - {"ens_id": "_id_", "dispatch_url": f"ws://localhost:{port}", "jobList": []} - ) + jobs_obj = { + "ens_id": "_id_", + "dispatch_url": f"ws://localhost:{port}", + "jobList": [], + } + print(os.getcwd()) + with open("jobs.json", mode="w+", encoding="utf-8") as f: # noqa: ASYNC230 + json.dump(jobs_obj, f) async def mock_run_method(self: ForwardModelRunner, *args, **kwargs): await self.put_event(Init([], 0, 0)) await self.put_event(Finish().with_error("overall bad run")) monkeypatch.setattr(ForwardModelRunner, "run", mock_run_method) - monkeypatch.setattr("builtins.open", mock_open(read_data=jobs_json)) + # monkeypatch.setattr(_ert.forward_model_runner.cli, "builtins.open", mock_open(read_data=jobs_json)) async with _mock_ws_task(host, port, []): with pytest.raises(ForwardModelRunnerException): await main(["script.py"])