-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
39 lines (33 loc) · 1.11 KB
/
conftest.py
File metadata and controls
39 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pytest
import asyncio
import motor.motor_asyncio
from beanie import init_beanie
from models import UserProgress
@pytest.fixture(scope="session")
def event_loop():
"""Create an instance of the default event loop for each test case."""
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()
@pytest.fixture(scope="session")
async def mongodb():
"""Create a MongoDB test database."""
client = motor.motor_asyncio.AsyncIOMotorClient(
"mongodb://localhost:27017"
)
db = client.test_devquest
# Initialize Beanie with the document models
await init_beanie(
database=db,
document_models=[UserProgress]
)
yield db
# Cleanup after all tests
await db.user_progress.delete_many({}) # Changed from drop to delete_many
client.close()
@pytest.fixture(autouse=True)
async def clean_db(mongodb):
"""Clean the UserProgress collection before each test."""
await mongodb.user_progress.delete_many({}) # Changed from drop to delete_many
await init_beanie(database=mongodb, document_models=[UserProgress])
yield