From 5e6a02095a74caf7ca6c350ac95e8e3f70780e00 Mon Sep 17 00:00:00 2001 From: Ian Bowden Date: Thu, 27 Jun 2024 16:27:12 -0400 Subject: [PATCH] created mock to override file open --- tests/application/test_main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/application/test_main.py b/tests/application/test_main.py index 173ea20d..0c23b795 100644 --- a/tests/application/test_main.py +++ b/tests/application/test_main.py @@ -167,7 +167,19 @@ def test_that_scan_implements_multiple_file_args(mock_container: MagicMock): ) -def test_that_update_with_new_pattern_succeeds(): +@pytest.fixture() +def mock_secureli_yaml_open_fn(mocker: MockerFixture) -> MagicMock: + mock_open = mocker.mock_open( + read_data=""" + {} + """ + ) + return mocker.patch("builtins.open", mock_open) + + +def test_that_update_with_new_pattern_succeeds( + mock_secureli_yaml_open_fn: MagicMock, # so we don't open and write to the actual secureli.yaml file +): result = CliRunner().invoke(secureli.main.app, ["update", "--new-pattern", "foo"]) assert result.exit_code == 0 assert result.stdout == ""