diff --git a/backend/tests/test_search_epc.py b/backend/tests/test_search_epc.py index 132f170f..9bb7c39a 100644 --- a/backend/tests/test_search_epc.py +++ b/backend/tests/test_search_epc.py @@ -1,11 +1,19 @@ import pytest import os from backend.SearchEpc import SearchEpc # Replace with your actual module name +from dotenv import load_dotenv -EPC_AUTH_TOKEN = os.getenv("EPC_AUTH_TOKEN") +# If this backend/.env file is present, we load it +if os.path.exists("backend/.env"): + load_dotenv("backend/.env") class TestSearchEpcIntegration: + + @pytest.fixture + def epc_auth_token(self): + return os.getenv("EPC_AUTH_TOKEN") + @pytest.mark.parametrize( "address, postcode, uprn, skip_os, lmk_key, n_old_epcs", [ @@ -27,7 +35,7 @@ class TestSearchEpcIntegration: ], ) - def test_find_property(self, address, postcode, uprn, skip_os, lmk_key, n_old_epcs): + def test_find_property(self, epc_auth_token, address, postcode, uprn, skip_os, lmk_key, n_old_epcs): """ Integration test for `find_property`, making actual API calls. """ @@ -39,7 +47,7 @@ class TestSearchEpcIntegration: address1=address, postcode=postcode, uprn=uprn, - auth_token=EPC_AUTH_TOKEN, + auth_token=epc_auth_token, os_api_key=os_api_key, )