From e9e56fb85dc513c8d63da78f8860d4f4691a82bc Mon Sep 17 00:00:00 2001 From: Shashank Reddy Boyapally Date: Mon, 22 Jan 2024 16:58:07 -0500 Subject: [PATCH] unit test refactor mock --- .github/workflows/unit_test.yml | 3 --- fmatch/tests/test_matcher.py | 11 +++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index 75cf786..1ece302 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -6,9 +6,6 @@ jobs: test: runs-on: ubuntu-latest - env: - ES_SERVER: ${{ secrets.ES_SERVER }} - steps: - name: Checkout code uses: actions/checkout@v2 diff --git a/fmatch/tests/test_matcher.py b/fmatch/tests/test_matcher.py index 8689b5e..f9e744f 100644 --- a/fmatch/tests/test_matcher.py +++ b/fmatch/tests/test_matcher.py @@ -5,6 +5,7 @@ #pylint: disable = missing-function-docstring #pylint: disable = import-error import os +from unittest.mock import patch from elasticsearch.exceptions import NotFoundError import pytest @@ -14,6 +15,7 @@ from fmatch.matcher import Matcher + @pytest.fixture def matcher_instance(): sample_output = { @@ -24,10 +26,11 @@ def matcher_instance(): ] } } - match = Matcher(index="perf-scale-ci") - match.es.search = lambda *args, **kwargs: sample_output - return match - + with patch('fmatch.matcher.Elasticsearch') as mock_es: + mock_es_instance = mock_es.return_value + mock_es_instance.search.return_value = sample_output + match = Matcher(index="perf-scale-ci") + return match def test_get_metadata_by_uuid_found(matcher_instance): uuid = "test_uuid"