diff --git a/app/test/conftest.py b/app/test/conftest.py index 460480d..fe64e5c 100644 --- a/app/test/conftest.py +++ b/app/test/conftest.py @@ -1,4 +1,5 @@ import pytest +import sqlite3 from selenium import webdriver @pytest.fixture @@ -9,3 +10,17 @@ def URL(): @pytest.fixture def driver(): return webdriver.Edge() # uncomment this line if you wish to run the test on your laptop + + +@pytest.fixture(autouse=True) +def restore_sqlite_database(): + ''' + Automatically restore SQLite database file app/db/wordfreqapp.db + using SQL statements from app/static/wordfreqapp.sql + ''' + con = sqlite3.connect('../db/wordfreqapp.db') + with con: + con.executescript('DROP TABLE IF EXISTS user;') + con.executescript('DROP TABLE IF EXISTS article;') + con.executescript(open('../static/wordfreqapp.sql', encoding='utf8').read()) + con.close()