I need to create db in fixture, do some manipulation with data (pass this part in code to simplify) in this db and use rows from this db as values for parameterized tests. But i couldn't force pytest execute fixture with creating db before executing def. of getting rows from db, so my tests fall with traceback "sqlite3.OperationalError: no such table: simple_table"
import pytest
import sqlite3
DB_PATH = r'test_db.db'
@pytest.fixture(scope='session', autouse=True)
def create_db():
con = sqlite3.connect(DB_PATH)
con.execute("CREATE TABLE simple_table (id int PRIMARY KEY)")
con.close()
yield
def take_values_from_db():
con = sqlite3.connect(DB_PATH)
values = con.cursor().execute(f"SELECT * from simple_table").fetchall()
con.close()
return list(values)
@pytest.mark.parametrize('value', take_values_from_db())
def test_1(value):
assert value == 1
Windows 10, Python 3.9, Pytest=6.2.5