Commit 86645bb
test: fix RuntimeWarnings from improper AsyncMock usage in tests (#1344)
* test: fix RuntimeWarnings from improper AsyncMock usage in tests
Fixed RuntimeWarnings caused by using AsyncMock() for synchronous methods
across multiple test files. The issue occurred when tests mocked sync methods
(like db.commit(), response.raise_for_status(), Redis.from_url()) with
AsyncMock, creating unawaited coroutines.
Changes:
- Use Mock()/MagicMock() for synchronous methods instead of AsyncMock()
- Fixed SQLAlchemy session methods (commit, refresh, close)
- Fixed HTTP response methods (raise_for_status)
- Fixed Redis client methods (from_url, pubsub, close)
- Fixed asyncio methods (create_task return values)
- Fixed event loop methods (call_soon_threadsafe)
- Removed unused event_loop fixture from conftest.py
Files modified:
- tests/unit/mcpgateway/test_reverse_proxy.py: Fixed process/task mocks
- tests/unit/mcpgateway/cache/test_session_registry.py: Fixed db session mocks
- tests/unit/mcpgateway/cache/test_session_registry_extended.py: Fixed Redis mocks
- tests/unit/mcpgateway/services/test_tool_service.py: Fixed db/HTTP mocks
- tests/unit/mcpgateway/services/test_logging_service_comprehensive.py: Fixed event loop mocks
- tests/unit/mcpgateway/services/test_role_service.py: Fixed patch.object usage
- tests/conftest.py: Removed deprecated event_loop fixture
Test results:
- 3108 tests passed
- Reduced RuntimeWarnings from many to 4 false-positive attributions
- All individual tests pass with no RuntimeWarnings
Signed-off-by: Jonathan Springer <[email protected]>
* chore: remove accidentally committed .orig file
Remove test_translate.py.orig which was accidentally included in the
previous commit. This is a merge/rebase artifact that should not be
tracked in version control.
Signed-off-by: Mihai Criveti <[email protected]>
---------
Signed-off-by: Jonathan Springer <[email protected]>
Signed-off-by: Mihai Criveti <[email protected]>
Co-authored-by: Mihai Criveti <[email protected]>1 parent a5a24f7 commit 86645bb
File tree
10 files changed
+181
-210
lines changed- mcpgateway
- tests
- unit/mcpgateway
- cache
- services
10 files changed
+181
-210
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 31 | | |
41 | 32 | | |
42 | 33 | | |
| |||
143 | 134 | | |
144 | 135 | | |
145 | 136 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | 137 | | |
158 | 138 | | |
159 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
857 | 857 | | |
858 | 858 | | |
859 | 859 | | |
| 860 | + | |
| 861 | + | |
860 | 862 | | |
861 | 863 | | |
862 | 864 | | |
863 | | - | |
| 865 | + | |
864 | 866 | | |
865 | 867 | | |
866 | 868 | | |
| |||
929 | 931 | | |
930 | 932 | | |
931 | 933 | | |
932 | | - | |
| 934 | + | |
933 | 935 | | |
934 | 936 | | |
935 | 937 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
| 584 | + | |
584 | 585 | | |
585 | 586 | | |
586 | 587 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
543 | | - | |
| 543 | + | |
| 544 | + | |
544 | 545 | | |
545 | 546 | | |
546 | 547 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1114 | 1114 | | |
1115 | 1115 | | |
1116 | 1116 | | |
1117 | | - | |
1118 | | - | |
| 1117 | + | |
| 1118 | + | |
1119 | 1119 | | |
1120 | 1120 | | |
1121 | 1121 | | |
| |||
1136 | 1136 | | |
1137 | 1137 | | |
1138 | 1138 | | |
1139 | | - | |
1140 | | - | |
| 1139 | + | |
| 1140 | + | |
1141 | 1141 | | |
1142 | 1142 | | |
1143 | 1143 | | |
| |||
1162 | 1162 | | |
1163 | 1163 | | |
1164 | 1164 | | |
1165 | | - | |
1166 | | - | |
| 1165 | + | |
| 1166 | + | |
1167 | 1167 | | |
1168 | 1168 | | |
1169 | 1169 | | |
| |||
1183 | 1183 | | |
1184 | 1184 | | |
1185 | 1185 | | |
1186 | | - | |
1187 | | - | |
| 1186 | + | |
| 1187 | + | |
1188 | 1188 | | |
1189 | 1189 | | |
1190 | 1190 | | |
| |||
1243 | 1243 | | |
1244 | 1244 | | |
1245 | 1245 | | |
1246 | | - | |
| 1246 | + | |
1247 | 1247 | | |
1248 | 1248 | | |
1249 | 1249 | | |
| |||
1268 | 1268 | | |
1269 | 1269 | | |
1270 | 1270 | | |
1271 | | - | |
| 1271 | + | |
1272 | 1272 | | |
1273 | 1273 | | |
1274 | 1274 | | |
| |||
1284 | 1284 | | |
1285 | 1285 | | |
1286 | 1286 | | |
1287 | | - | |
| 1287 | + | |
1288 | 1288 | | |
1289 | 1289 | | |
1290 | 1290 | | |
| |||
1314 | 1314 | | |
1315 | 1315 | | |
1316 | 1316 | | |
1317 | | - | |
| 1317 | + | |
1318 | 1318 | | |
1319 | 1319 | | |
1320 | 1320 | | |
| |||
2038 | 2038 | | |
2039 | 2039 | | |
2040 | 2040 | | |
2041 | | - | |
| 2041 | + | |
2042 | 2042 | | |
2043 | 2043 | | |
2044 | 2044 | | |
| |||
2150 | 2150 | | |
2151 | 2151 | | |
2152 | 2152 | | |
2153 | | - | |
| 2153 | + | |
2154 | 2154 | | |
2155 | 2155 | | |
2156 | 2156 | | |
| |||
2242 | 2242 | | |
2243 | 2243 | | |
2244 | 2244 | | |
2245 | | - | |
| 2245 | + | |
2246 | 2246 | | |
2247 | 2247 | | |
2248 | 2248 | | |
| |||
2283 | 2283 | | |
2284 | 2284 | | |
2285 | 2285 | | |
2286 | | - | |
| 2286 | + | |
2287 | 2287 | | |
2288 | 2288 | | |
2289 | 2289 | | |
| |||
2327 | 2327 | | |
2328 | 2328 | | |
2329 | 2329 | | |
2330 | | - | |
| 2330 | + | |
2331 | 2331 | | |
2332 | 2332 | | |
2333 | 2333 | | |
| |||
2371 | 2371 | | |
2372 | 2372 | | |
2373 | 2373 | | |
2374 | | - | |
| 2374 | + | |
2375 | 2375 | | |
2376 | 2376 | | |
2377 | 2377 | | |
| |||
2414 | 2414 | | |
2415 | 2415 | | |
2416 | 2416 | | |
2417 | | - | |
| 2417 | + | |
2418 | 2418 | | |
2419 | 2419 | | |
2420 | 2420 | | |
| |||
Lines changed: 14 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
183 | | - | |
| 182 | + | |
184 | 183 | | |
185 | 184 | | |
186 | 185 | | |
| |||
194 | 193 | | |
195 | 194 | | |
196 | 195 | | |
197 | | - | |
198 | | - | |
| 196 | + | |
199 | 197 | | |
200 | 198 | | |
201 | 199 | | |
| |||
665 | 663 | | |
666 | 664 | | |
667 | 665 | | |
668 | | - | |
| 666 | + | |
669 | 667 | | |
670 | 668 | | |
671 | 669 | | |
672 | 670 | | |
673 | 671 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
678 | 675 | | |
679 | | - | |
680 | | - | |
| 676 | + | |
| 677 | + | |
681 | 678 | | |
682 | 679 | | |
683 | 680 | | |
| |||
690 | 687 | | |
691 | 688 | | |
692 | 689 | | |
693 | | - | |
| 690 | + | |
694 | 691 | | |
695 | 692 | | |
696 | 693 | | |
697 | 694 | | |
698 | 695 | | |
699 | | - | |
700 | | - | |
| 696 | + | |
701 | 697 | | |
702 | | - | |
703 | | - | |
704 | | - | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
0 commit comments