Skip to content

Commit fe8a0dd

Browse files
committed
fix test dependencies
1 parent edd3533 commit fe8a0dd

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

tests/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ birch
77
# to be able to run `python setup.py checkdocs`
88
collective.checkdocs
99
pygments
10+
# the memory core tests dataframe caching
11+
import pandas

tests/test_mongo_core.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
11
"""Testing the MongoDB core of cachier."""
22

3+
# standard library imports
34
import datetime
45
import hashlib
56
import platform
67
import queue
78
import sys
89
import threading
9-
import warnings
1010
from random import random
1111
from time import sleep
1212
from urllib.parse import quote_plus
1313

14+
# third-party imports
15+
import pytest
16+
from birch import Birch # type: ignore[import-not-found]
1417
try:
1518
import pandas as pd
1619
except (ImportError, ModuleNotFoundError):
1720
pd = None
18-
warnings.warn("pandas is not installed; tests requiring pandas will fail!")
21+
print("pandas is not installed; tests requiring pandas will fail!")
1922

2023
try:
2124
import pymongo
2225
from pymongo.errors import OperationFailure
2326
from pymongo.mongo_client import MongoClient
24-
from pymongo_inmemory import MongoClient as InMemoryMongoClient
2527
except (ImportError, ModuleNotFoundError):
28+
print("pymongo is not installed; tests requiring pymongo will fail!")
2629
pymongo = None
27-
MongoClient = None
28-
InMemoryMongoClient = None
2930
OperationFailure = None
30-
warnings.warn(
31-
"pymongo is not installed; tests requiring pymongo will fail!"
32-
)
33-
import pytest
34-
from birch import Birch # type: ignore[import-not-found]
31+
# define a mock MongoClient class that will raise an exception
32+
# on init, warning that pymongo is not installed
33+
class MongoClient:
34+
def __init__(self, *args, **kwargs):
35+
raise ImportError("pymongo is not installed!")
36+
try:
37+
from pymongo_inmemory import MongoClient as InMemoryMongoClient
38+
except (ImportError, ModuleNotFoundError):
39+
class InMemoryMongoClient:
40+
def __init__(self, *args, **kwargs):
41+
raise ImportError("pymongo_inmemory is not installed!")
42+
print("pymongo_inmemory is not installed; "
43+
"in-memory MongoDB tests will fail!")
3544

45+
# local imports
3646
from cachier import cachier
3747
from cachier.config import CacheEntry
3848
from cachier.cores.base import RecalculationNeeded
3949
from cachier.cores.mongo import _MongoCore
4050

51+
4152
# === Enables testing vs a real MongoDB instance ===
4253

4354

0 commit comments

Comments
 (0)