-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
34 lines (28 loc) · 852 Bytes
/
conftest.py
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
import random
import pytest
collect_ignore = [
'jaraco/mongodb/pmxbot.py',
# disable move-gridfs check, as it causes output capturing
# to be disabled. See pytest-dev/pytest#3752.
'jaraco/mongodb/move-gridfs.py',
]
@pytest.fixture(scope='function')
def database(request, mongodb_instance):
"""
Return a clean MongoDB database suitable for testing.
"""
db_name = request.node.name.replace('.', '_')
database = mongodb_instance.get_connection()[db_name]
yield database
database.client.drop_database(db_name)
@pytest.fixture()
def bulky_collection(database):
"""
Generate a semi-bulky collection with a few dozen random
documents.
"""
coll = database.bulky
for _id in range(100):
doc = dict(_id=_id, val=random.randint(1, 100))
coll.insert_one(doc)
return coll