Skip to content

Commit 4f1b1d8

Browse files
Nir.TalNir.Tal
authored andcommitted
chore: db fixture
1 parent e4f69df commit 4f1b1d8

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

tests/base_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from abc import ABC
12
from typing import Union
23

34
from selenium.webdriver import Chrome, Edge, Firefox
@@ -14,7 +15,7 @@
1415
from utilities.vrt_helper import VrtHelper
1516

1617

17-
class BaseTest:
18+
class BaseTest(ABC):
1819
driver: Union[Chrome, Firefox, Edge]
1920
wait: WebDriverWait
2021
about_page: AboutPage

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from _pytest.nodes import Item
1414
from dotenv import load_dotenv
1515
from mailinator import Mailinator
16+
from mysql.connector import MySQLConnection
1617
from requests_toolbelt.utils import dump
1718
from selenium import webdriver
1819
from selenium.webdriver.support.event_firing_webdriver import EventFiringWebDriver
@@ -100,6 +101,14 @@ def mailinator_helper() -> MailinatorHelper:
100101
)
101102

102103

104+
@pytest.fixture(scope="session")
105+
def db_connection():
106+
"""Fixture to establish a database connection."""
107+
connection = MySQLConnection(user="root", password="1234", database="world")
108+
yield connection
109+
connection.close()
110+
111+
103112
@pytest.fixture(scope="session")
104113
def vrt_helper():
105114
"""Fixture for creating a Visual Regression Tracker (VRT) helper object.

tests/db_test.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import allure
22
import pytest
33
from assertpy import assert_that
4-
from mysql.connector import MySQLConnection
54

65

76
@pytest.mark.skip(reason="requires database connection")
87
class TestDatabaseExample:
98
@allure.title("Verify population amounts")
10-
def test_verify_population_amount(self):
11-
with MySQLConnection(
12-
user="root", password="1234", database="world"
13-
) as connection:
14-
cursor = connection.cursor()
15-
cursor.execute("select Population from city where CountryCode='DNK'")
16-
population_amount: list[int] = [item[0] for item in cursor.fetchall()]
17-
assert_that(population_amount).described_as("population amount").is_equal_to(
18-
[495699, 284846, 183912, 161161, 90327]
19-
)
9+
def test_verify_population_amount(self, db_connection):
10+
with db_connection.cursor() as cursor:
11+
cursor.execute("SELECT Population FROM city WHERE CountryCode='DNK'")
12+
population_amount = [item[0] for item in cursor.fetchall()]
13+
assert_that(population_amount).described_as(
14+
"population amount"
15+
).is_equal_to([495699, 284846, 183912, 161161, 90327])

0 commit comments

Comments
 (0)