Skip to content

Commit 004be21

Browse files
committed
fixes and readme updates
1 parent e0f8892 commit 004be21

6 files changed

Lines changed: 60 additions & 31 deletions

File tree

CLAUDE.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,6 @@ ______________________________________________________________________
208208
- `make services-start` - Start all Docker containers
209209
- `make services-stop` - Stop all Docker containers
210210

211-
**MongoDB-Specific Testing (Legacy):**
212-
213-
The MongoDB-specific script still works:
214-
215-
```bash
216-
./scripts/test-mongo-local.sh # MongoDB only
217-
./scripts/test-mongo-local.sh --mode also-local # MongoDB + memory, pickle, maxage
218-
```
219-
220211
**Available Cores:**
221212

222213
- `mongo` - MongoDB backend

README.rst

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,22 +541,25 @@ Running MongoDB tests against a live MongoDB instance
541541

542542
.. code-block:: bash
543543
544-
./scripts/test-mongo-local.sh # MongoDB tests only (default)
545-
./scripts/test-mongo-local.sh --mode also-local # MongoDB + memory, pickle, maxage tests
544+
# Test MongoDB only
545+
./scripts/test-local.sh mongo
546+
547+
# Test MongoDB with local backends
548+
./scripts/test-local.sh mongo memory pickle
546549
547550
This script automatically handles Docker container lifecycle, environment variables, and cleanup. Additional options:
548551

549-
- ``--mode also-local``: Include memory, pickle, and maxage tests alongside MongoDB tests
550-
- ``--keep-running``: Keep MongoDB container running after tests
551-
- ``--verbose``: Show verbose output
552-
- ``--coverage-html``: Generate HTML coverage report
552+
- ``-v, --verbose``: Show verbose output
553+
- ``-k, --keep-running``: Keep containers running after tests
554+
- ``-h, --html-coverage``: Generate HTML coverage report
553555

554556
**Option 2: Using Make**
555557

556558
.. code-block:: bash
557559
558-
make test-mongo-local # Run tests with Docker MongoDB
559-
make test-mongo-inmemory # Run tests with in-memory MongoDB (default)
560+
make test-mongo-local # Run MongoDB tests with Docker
561+
make test-all-local # Run all backends with Docker
562+
make test-mongo-inmemory # Run with in-memory MongoDB (default)
560563
561564
**Option 3: Manual setup**
562565

@@ -578,6 +581,28 @@ Contributors are encouraged to test against a real MongoDB instance before submi
578581
**HOWEVER, the tests run against a live MongoDB instance when you submit a PR are the determining tests for deciding whether your code functions correctly against MongoDB.**
579582

580583

584+
Testing all backends locally
585+
-----------------------------
586+
587+
To test all cachier backends (MongoDB, Redis, SQL, Memory, Pickle) locally with Docker:
588+
589+
.. code-block:: bash
590+
591+
# Test all backends at once
592+
./scripts/test-local.sh all
593+
594+
# Test only external backends (MongoDB, Redis, SQL)
595+
./scripts/test-local.sh external
596+
597+
# Test specific combinations
598+
./scripts/test-local.sh mongo redis
599+
600+
# Keep containers running for debugging
601+
./scripts/test-local.sh all -k
602+
603+
The unified test script automatically manages Docker containers, installs required dependencies, and runs the appropriate test suites. See ``scripts/README-local-testing.md`` for detailed documentation.
604+
605+
581606
Adding documentation
582607
--------------------
583608

scripts/README-local-testing.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,6 @@ The script automatically sets the required environment variables:
177177
docker rm cachier-test-mongo cachier-test-redis cachier-test-postgres
178178
```
179179

180-
## Integration with test-mongo-local.sh
181-
182-
The previous `test-mongo-local.sh` script still works and is now a specialized version of the general `test-local.sh`:
183-
184-
```bash
185-
# These are equivalent:
186-
./scripts/test-mongo-local.sh
187-
./scripts/test-local.sh mongo
188-
189-
# These are equivalent:
190-
./scripts/test-mongo-local.sh --mode also-local
191-
./scripts/test-local.sh mongo memory pickle
192-
```
193180

194181
## Best Practices
195182

tests/conftest.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Pytest configuration and shared fixtures for cachier tests."""
2+
3+
import pytest
4+
5+
6+
@pytest.fixture(scope="session", autouse=True)
7+
def cleanup_mongo_clients():
8+
"""Clean up any MongoDB clients created during tests.
9+
10+
This fixture runs automatically after all tests complete.
11+
"""
12+
# Let tests run
13+
yield
14+
15+
# Cleanup after all tests
16+
try:
17+
from tests.test_mongo_core import _test_mongetter
18+
if hasattr(_test_mongetter, "client"):
19+
# Close the MongoDB client to avoid ResourceWarning
20+
_test_mongetter.client.close()
21+
# Remove the client attribute so future test runs start fresh
22+
delattr(_test_mongetter, "client")
23+
except (ImportError, AttributeError):
24+
# If the module wasn't imported or client wasn't created, nothing to clean up
25+
pass

tests/test_core_lookup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44

55
from cachier import cachier, get_global_params
6-
from cachier.cores.mongo import MissingMongetter
76

87

98
def test_get_default_params():

tests/test_mongo_core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import pymongo
2626
from pymongo.errors import OperationFailure
2727
from pymongo.mongo_client import MongoClient
28+
from cachier.cores.mongo import MissingMongetter
2829
except (ImportError, ModuleNotFoundError):
2930
print("pymongo is not installed; tests requiring pymongo will fail!")
3031
pymongo = None
3132
OperationFailure = None
33+
MissingMongetter = None
3234

3335
# define a mock MongoClient class that will raise an exception
3436
# on init, warning that pymongo is not installed

0 commit comments

Comments
 (0)