Define a fixture that restarts flask app for each test run

Bug533-Yuyikai
Lan Hui 2024-04-10 14:44:23 +08:00
parent 77a3adb546
commit 64b9c51fab
1 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,8 @@
import pytest import pytest
import sqlite3 import sqlite3
import time
from selenium import webdriver from selenium import webdriver
from pathlib import Path
@pytest.fixture @pytest.fixture
def URL(): def URL():
@ -12,7 +14,7 @@ def driver():
return webdriver.Edge() # uncomment this line if you wish to run the test on your laptop return webdriver.Edge() # uncomment this line if you wish to run the test on your laptop
@pytest.fixture(autouse=True) @pytest.fixture
def restore_sqlite_database(): def restore_sqlite_database():
''' '''
Automatically restore SQLite database file app/db/wordfreqapp.db Automatically restore SQLite database file app/db/wordfreqapp.db
@ -24,3 +26,9 @@ def restore_sqlite_database():
con.executescript('DROP TABLE IF EXISTS article;') con.executescript('DROP TABLE IF EXISTS article;')
con.executescript(open('../static/wordfreqapp.sql', encoding='utf8').read()) con.executescript(open('../static/wordfreqapp.sql', encoding='utf8').read())
con.close() con.close()
@pytest.fixture(autouse=True)
def restart_englishpal(restore_sqlite_database):
(Path(__file__).parent / '../main.py').touch()
time.sleep(1)