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
start_session method for client
  • Loading branch information
assigdev committed Oct 4, 2018
commit d6fc34b92a144085c54312539fe6bd273dd6a0d0
24 changes: 12 additions & 12 deletions pytest_async_mongodb/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ def __getattribute__(self, name):
return attr


class Session:
async def __aenter__(self):
await asyncio.sleep(0)

async def __aexit__(self, exc_type, exc, tb):
await asyncio.sleep(0)


class AsyncCollection(AsyncClassMethod, mongomock.Collection):

ASYNC_METHODS = [
Expand Down Expand Up @@ -99,10 +91,6 @@ async def find_one(self, filter=None, *args, **kwargs):
except StopIteration:
return None

async def start_session(self, **kwargs):
await asyncio.sleep(0)
return Session()


class AsyncDatabase(AsyncClassMethod, mongomock.Database):

Expand All @@ -118,6 +106,14 @@ def get_collection(self, name, codec_options=None, read_preference=None,
return collection


class Session:
async def __aenter__(self):
await asyncio.sleep(0)

async def __aexit__(self, exc_type, exc, tb):
await asyncio.sleep(0)


class AsyncMockMongoClient(mongomock.MongoClient):

def get_database(self, name, codec_options=None, read_preference=None,
Expand All @@ -127,6 +123,10 @@ def get_database(self, name, codec_options=None, read_preference=None,
db = self._databases[name] = AsyncDatabase(self, name)
return db

async def start_session(self, **kwargs):
await asyncio.sleep(0)
return Session()


@pytest.fixture(scope='function')
async def async_mongodb(pytestconfig):
Expand Down