From 74c052148e43593d5b8db3f92b3cfb7bb655e9f1 Mon Sep 17 00:00:00 2001 From: MJedr Date: Mon, 2 Oct 2023 15:34:27 +0200 Subject: [PATCH] update conftest in matomo-api --- matomo-api/tests/conftest.py | 6 ++++++ matomo-api/tests/test_api.py | 8 +++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/matomo-api/tests/conftest.py b/matomo-api/tests/conftest.py index 8773d57..f0eaa8b 100644 --- a/matomo-api/tests/conftest.py +++ b/matomo-api/tests/conftest.py @@ -1,5 +1,6 @@ import psycopg2 import pytest +from api import MatomoAPI @pytest.fixture(scope="module") @@ -45,3 +46,8 @@ def updated_env(monkeypatch): ) for env_name, env_value in matomo_api_kwargs.items(): monkeypatch.setenv(env_name, env_value) + + +@pytest.fixture(scope='function') +def matomo_api(): + yield MatomoAPI() diff --git a/matomo-api/tests/test_api.py b/matomo-api/tests/test_api.py index b33958c..49938fa 100644 --- a/matomo-api/tests/test_api.py +++ b/matomo-api/tests/test_api.py @@ -1,9 +1,7 @@ from datetime import datetime import pytest -from api import MatomoAPI -matomo_api = MatomoAPI() TEST_DAY = day = datetime.strptime("2023-10-02", "%Y-%m-%d") @@ -12,7 +10,7 @@ filter_headers=["authorization", "Set-Cookie"], filter_query_parameters=["token_auth", "idSite"], ) -def test_matomo_api_get_unique_visitors(): +def test_matomo_api_get_unique_visitors(matomo_api): visitors = matomo_api.get_unique_visitors(date=TEST_DAY) assert visitors > 0 @@ -21,7 +19,7 @@ def test_matomo_api_get_unique_visitors(): filter_headers=["authorization", "Set-Cookie"], filter_query_parameters=["token_auth", "idSite"], ) -def test_matomo_api_get_visits_per_day(): +def test_matomo_api_get_visits_per_day(matomo_api): visitors = matomo_api.get_visits_per_day(date=TEST_DAY) assert visitors > 0 @@ -30,7 +28,7 @@ def test_matomo_api_get_visits_per_day(): filter_headers=["authorization", "Set-Cookie"], filter_query_parameters=["token_auth", "idSite"], ) -def test_matomo_fetch_inspire_statistics(db): +def test_matomo_fetch_inspire_statistics(db, matomo_api): _, db_cursor = db matomo_api.fetch_inspire_statistics(date=TEST_DAY)