Skip to content

Commit

Permalink
Abstract required mocks for get_full_manifest tests to reduce dupli…
Browse files Browse the repository at this point in the history
…cation

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.
  • Loading branch information
QMalcolm committed May 14, 2024
1 parent a54d734 commit 791ec1d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tests/unit/parser/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,25 @@ 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
mocker.patch(
"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(
Expand All @@ -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,
Expand Down

0 comments on commit 791ec1d

Please sign in to comment.