Skip to content

Commit 2cd147e

Browse files
tests(pymongo) support pymongo 4.0 in tests (backport #3037) (#3038)
* tests(pymongo) support pymongo 4.0 in tests (#3037) (cherry picked from commit b684836) # Conflicts: # riotfile.py * Apply suggestions from code review Co-authored-by: Brett Langdon <[email protected]>
1 parent 56e76a0 commit 2cd147e

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

riotfile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,16 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION):
417417
">=3.7,<3.8",
418418
">=3.8,<3.9",
419419
">=3.9,<3.10",
420+
],
421+
},
422+
),
423+
Venv(
424+
pys=select_pys(min_version="3.6"),
425+
pkgs={
426+
"pymongo": [
420427
">=3.10,<3.11",
421428
">=3.12,<3.13",
429+
">=4.0,<4.1",
422430
latest,
423431
],
424432
},

tests/contrib/pymongo/test.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,22 @@ def test_delete(self):
140140
songs = db[collection_name]
141141
songs.insert_many(input_songs)
142142

143+
def count(col, *args, **kwargs):
144+
if pymongo.version_tuple >= (4, 0):
145+
return col.count_documents(*args, **kwargs)
146+
return col.count(*args, **kwargs)
147+
143148
# test delete one
144149
af = {"artist": "Neil"}
145-
assert songs.count(af) == 2
150+
assert count(songs, af) == 2
146151
songs.delete_one(af)
147-
assert songs.count(af) == 1
152+
assert count(songs, af) == 1
148153

149154
# test delete many
150155
af = {"artist": "Leonard"}
151-
assert songs.count(af) == 2
156+
assert count(songs, af) == 2
152157
songs.delete_many(af)
153-
assert songs.count(af) == 0
158+
assert count(songs, af) == 0
154159

155160
# ensure all is traced.
156161
spans = tracer.pop()
@@ -165,16 +170,28 @@ def test_delete(self):
165170
assert span.meta.get("out.host")
166171
assert span.metrics.get("out.port")
167172

168-
expected_resources = [
169-
"drop here.are.songs",
170-
"count here.are.songs",
171-
"count here.are.songs",
172-
"count here.are.songs",
173-
"count here.are.songs",
174-
'delete here.are.songs {"artist": "?"}',
175-
'delete here.are.songs {"artist": "?"}',
176-
"insert here.are.songs",
177-
]
173+
if pymongo.version_tuple >= (4, 0):
174+
expected_resources = [
175+
"drop here.are.songs",
176+
"aggregate here.are.songs",
177+
"aggregate here.are.songs",
178+
"aggregate here.are.songs",
179+
"aggregate here.are.songs",
180+
'delete here.are.songs {"artist": "?"}',
181+
'delete here.are.songs {"artist": "?"}',
182+
"insert here.are.songs",
183+
]
184+
else:
185+
expected_resources = [
186+
"drop here.are.songs",
187+
"count here.are.songs",
188+
"count here.are.songs",
189+
"count here.are.songs",
190+
"count here.are.songs",
191+
'delete here.are.songs {"artist": "?"}',
192+
'delete here.are.songs {"artist": "?"}',
193+
"insert here.are.songs",
194+
]
178195

179196
assert sorted(expected_resources) == sorted(s.resource for s in spans)
180197

0 commit comments

Comments
 (0)