diff --git a/tests/base_test.py b/tests/base_test.py index 05d15bd427..7ae22b342c 100644 --- a/tests/base_test.py +++ b/tests/base_test.py @@ -1,3 +1,4 @@ +from abc import ABC from typing import Union from selenium.webdriver import Chrome, Edge, Firefox @@ -14,7 +15,7 @@ from utilities.vrt_helper import VrtHelper -class BaseTest: +class BaseTest(ABC): driver: Union[Chrome, Firefox, Edge] wait: WebDriverWait about_page: AboutPage diff --git a/tests/conftest.py b/tests/conftest.py index 673535e2c6..504639fa5b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,6 +13,7 @@ from _pytest.nodes import Item from dotenv import load_dotenv from mailinator import Mailinator +from mysql.connector import MySQLConnection from requests_toolbelt.utils import dump from selenium import webdriver from selenium.webdriver.support.event_firing_webdriver import EventFiringWebDriver @@ -100,6 +101,14 @@ def mailinator_helper() -> MailinatorHelper: ) +@pytest.fixture(scope="session") +def db_connection(): + """Fixture to establish a database connection.""" + connection = MySQLConnection(user="root", password="1234", database="world") + yield connection + connection.close() + + @pytest.fixture(scope="session") def vrt_helper(): """Fixture for creating a Visual Regression Tracker (VRT) helper object. diff --git a/tests/db_test.py b/tests/db_test.py index 83d45e1c7c..aebb610818 100644 --- a/tests/db_test.py +++ b/tests/db_test.py @@ -1,19 +1,15 @@ import allure import pytest from assertpy import assert_that -from mysql.connector import MySQLConnection @pytest.mark.skip(reason="requires database connection") class TestDatabaseExample: @allure.title("Verify population amounts") - def test_verify_population_amount(self): - with MySQLConnection( - user="root", password="1234", database="world" - ) as connection: - cursor = connection.cursor() - cursor.execute("select Population from city where CountryCode='DNK'") - population_amount: list[int] = [item[0] for item in cursor.fetchall()] - assert_that(population_amount).described_as("population amount").is_equal_to( - [495699, 284846, 183912, 161161, 90327] - ) + def test_verify_population_amount(self, db_connection): + with db_connection.cursor() as cursor: + cursor.execute("SELECT Population FROM city WHERE CountryCode='DNK'") + population_amount = [item[0] for item in cursor.fetchall()] + assert_that(population_amount).described_as( + "population amount" + ).is_equal_to([495699, 284846, 183912, 161161, 90327])