Coverage for tests/conftest.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-20 21:23 +0000

1import sys 

2import os 

3 

4# Add the project root directory to Python path 

5sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) 

6 

7from flask import current_app 

8from config import TestingConfig 

9import pytest 

10from app import create_app, db 

11from sqlalchemy.sql import text 

12from time import sleep 

13from sqlalchemy import delete 

14 

15 

16@pytest.fixture() 

17def app(): 

18 """ 

19 Author: Troy Witmer 

20 Dadte: 02/20/2025 

21 Description: pytest fixture to create a fresh application and database (sqlite in memory) 

22 for each test. then removes drops all db after test. 

23 """ 

24 app = create_app(config_class=TestingConfig) 

25 

26 with app.app_context(): 

27 db.create_all() 

28 db.session.execute(text("CREATE EXTENSION IF NOT EXISTS vector")) 

29 

30 yield app 

31 

32 with app.app_context(): 

33 db.drop_all() 

34 

35 

36@pytest.fixture() 

37def client(app): 

38 """ 

39 Author: Troy Witmer 

40 Date: 02/20/2025 

41 Description: pytest fixture to create a sample client () 

42 """ 

43 return app.test_client() 

44 

45 

46@pytest.fixture() 

47def clean_vector_db(app): 

48 """ 

49 Fixture to ensure a clean vector database before and after the test. 

50 """ 

51 with app.app_context(): 

52 vector_db = current_app.vector_db 

53 db.session.execute(delete(vector_db.EmbeddingStore)) # Clear embeddings 

54 db.session.commit() 

55 yield 

56 with app.app_context(): 

57 db.session.execute(delete(vector_db.EmbeddingStore)) # Clean up after test 

58 db.session.commit()