From 791ec1d64f569a59d817a9d5e0fb4b95a4b291cf Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 9 May 2024 10:42:40 -0700 Subject: [PATCH] Abstract required mocks for `get_full_manifest` tests to reduce duplication There are a set of required mocks that `get_full_manifest` unit tests need. Instead of doing these mocks in each test, we've abstracted these mocks into a reusable function. I did try to do this as a fixture, but for some reaosn the mocks didn't actually propagate when I did that. --- tests/unit/parser/test_manifest.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/unit/parser/test_manifest.py b/tests/unit/parser/test_manifest.py index 66f400fb9a1..f5b4c411b4e 100644 --- a/tests/unit/parser/test_manifest.py +++ b/tests/unit/parser/test_manifest.py @@ -114,13 +114,9 @@ def test_partial_parse_safe_update_project_parser_files_partially( class TestGetFullManifest: - def test_write_perf_info( - self, - manifest: Manifest, - mock_project: MagicMock, - mock_adapter: MagicMock, - mocker: MockerFixture, - ) -> None: + def set_required_mocks( + self, mocker: MockerFixture, manifest: Manifest, mock_adapter: MagicMock + ): mocker.patch("dbt.parser.manifest.get_adapter").return_value = mock_adapter mocker.patch("dbt.parser.manifest.ManifestLoader.load").return_value = manifest mocker.patch("dbt.parser.manifest._check_manifest").return_value = None @@ -128,6 +124,15 @@ def test_write_perf_info( "dbt.parser.manifest.ManifestLoader.save_macros_to_adapter" ).return_value = None mocker.patch("dbt.tracking.active_user").return_value = User(None) + + def test_write_perf_info( + self, + manifest: Manifest, + mock_project: MagicMock, + mock_adapter: MagicMock, + mocker: MockerFixture, + ) -> None: + self.set_required_mocks(mocker, manifest, mock_adapter) write_perf_info = mocker.patch("dbt.parser.manifest.ManifestLoader.write_perf_info") ManifestLoader.get_full_manifest( @@ -149,13 +154,7 @@ def test_reset( mock_adapter: MagicMock, mocker: MockerFixture, ) -> None: - mocker.patch("dbt.parser.manifest.get_adapter").return_value = mock_adapter - mocker.patch("dbt.parser.manifest.ManifestLoader.load").return_value = manifest - mocker.patch("dbt.parser.manifest._check_manifest").return_value = None - mocker.patch( - "dbt.parser.manifest.ManifestLoader.save_macros_to_adapter" - ).return_value = None - mocker.patch("dbt.tracking.active_user").return_value = User(None) + self.set_required_mocks(mocker, manifest, mock_adapter) ManifestLoader.get_full_manifest( config=mock_project,