@@ -134,7 +134,7 @@ def __exit__(self, t, value, traceback):
134134
135135
136136class query_counter :
137- """Query_counter context manager to get the number of queries.
137+ """query_counter context manager to get the number of queries.
138138 This works by updating the `profiling_level` of the database so that all queries get logged,
139139 resetting the db.system.profile collection at the beginning of the context and counting the new entries.
140140
@@ -150,11 +150,11 @@ class User(Document):
150150
151151 with query_counter() as q:
152152 user = User(name='Bob')
153- assert q == 0 # no query fired yet
153+ assert q == 0 # no query fired yet
154154 user.save()
155- assert q == 1 # 1 query was fired, an 'insert'
155+ assert q == 1 # 1 query was fired, an 'insert'
156156 user_bis = User.objects().first()
157- assert q == 2 # a 2nd query was fired, a 'find_one'
157+ assert q == 2 # a 2nd query was fired, a 'find_one'
158158
159159 Be aware that:
160160
@@ -242,7 +242,7 @@ def _get_count(self):
242242
243243
244244class async_query_counter :
245- """Query_counter context manager to get the number of queries.
245+ """async_query_counter context manager to get the number of queries.
246246 This works by updating the `profiling_level` of the database so that all queries get logged,
247247 resetting the db.system.profile collection at the beginning of the context and counting the new entries.
248248
@@ -256,13 +256,13 @@ class async_query_counter:
256256 class User(Document):
257257 name = StringField()
258258
259- with query_counter () as q:
259+ with async_query_counter () as q:
260260 user = User(name='Bob')
261- assert q == 0 # no query fired yet
262- user.save ()
263- assert q == 1 # 1 query was fired, an 'insert'
261+ assert await q.eq(0) # no query fired yet
262+ user.asave ()
263+ assert await q.eq(1) # 1 query was fired, an 'insert'
264264 user_bis = User.objects().first()
265- assert q == 2 # a 2nd query was fired, a 'find_one'
265+ assert await q.eq(2) # a 2nd query was fired, a 'find_one'
266266
267267 Be aware that:
268268
0 commit comments