Skip to content

Commit 2acd21d

Browse files
committed
safe import of optional dependencies in mongodb core tests
1 parent f5288ec commit 2acd21d

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

tests/test_mongo_core.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,34 @@
55
import platform
66
import queue
77
import sys
8+
import warnings
89
import threading
910
from random import random
1011
from time import sleep
1112
from urllib.parse import quote_plus
1213

13-
import pandas as pd
14-
import pymongo
14+
try:
15+
import pandas as pd
16+
except ImportError:
17+
pd = None
18+
warnings.warn(
19+
"pandas is not installed; tests requiring pandas will fail!")
20+
21+
try:
22+
import pymongo
23+
from pymongo.errors import OperationFailure
24+
from pymongo.mongo_client import MongoClient
25+
from pymongo_inmemory import MongoClient as InMemoryMongoClient
26+
except ImportError:
27+
pymongo = None
28+
MongoClient = None
29+
InMemoryMongoClient = None
30+
OperationFailure = None
31+
warnings.warn(
32+
"pymongo is not installed; tests requiring pymongo will fail!"
33+
)
1534
import pytest
1635
from birch import Birch # type: ignore[import-not-found]
17-
from pymongo.errors import OperationFailure
18-
from pymongo.mongo_client import MongoClient
19-
from pymongo_inmemory import MongoClient as InMemoryMongoClient
2036

2137
from cachier import cachier
2238
from cachier.config import CacheEntry

0 commit comments

Comments
 (0)