Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change sync load fixture to async
  • Loading branch information
assigdev committed Oct 4, 2018
commit 6fbc9cbce45fe532fd8012a9287109fcee4c07d7
10 changes: 5 additions & 5 deletions pytest_async_mongodb/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def async_mongodb(pytestconfig):
client = AsyncMockMongoClient()
db = client['pytest']
await clean_database(db)
load_fixtures(db, pytestconfig)
await load_fixtures(db, pytestconfig)
return db


Expand All @@ -143,7 +143,7 @@ async def clean_database(db):
db.drop_collection(name)


def load_fixtures(db, config):
async def load_fixtures(db, config):
option_dir = config.getoption('async_mongodb_fixture_dir')
ini_dir = config.getini('async_mongodb_fixture_dir')
fixtures = config.getini('async_mongodb_fixtures')
Expand All @@ -156,10 +156,10 @@ def load_fixtures(db, config):
selected = fixtures and collection in fixtures
if selected and supported:
path = os.path.join(basedir, file_name)
load_fixture(db, collection, path, file_format)
await load_fixture(db, collection, path, file_format)


def load_fixture(db, collection, path, file_format):
async def load_fixture(db, collection, path, file_format):
if file_format == 'json':
loader = functools.partial(json.load, object_hook=json_util.object_hook)
elif file_format == 'yaml':
Expand All @@ -173,4 +173,4 @@ def load_fixture(db, collection, path, file_format):
_cache[path] = docs = loader(fp)

for document in docs:
db[collection].insert(document)
await db[collection].insert_one(document)