Skip to content

Commit 301f7bb

Browse files
committed
Suppress warnings in tests and add instructions for testing in README. Update .gitignore.
1 parent 9c09d39 commit 301f7bb

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ build/
1111
.coverage
1212
**/htmlcov/**
1313
dist/*
14+
.python-version

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class Incrementer:
4747
#### How to invalidate a cache
4848

4949
```python
50-
5150
foo(1)
5251
foo.invalidate(1)
5352

@@ -61,6 +60,30 @@ Incrementer.get_datetime()
6160
Incrementer.get_datetime.invalidate()
6261
```
6362

63+
#### How to run tests
64+
65+
1. Create and activate a new Python virtual environment using the package manager of your choice (e.g., `pyenv-virtualenv`, `virtualenv`, etc.).
66+
67+
2. Install requirements.
68+
69+
```bash
70+
pip install -r requirements.txt
71+
```
72+
73+
3. Install the `django_cache_helper` package in editable mode
74+
75+
```bash
76+
pip install -e .
77+
```
78+
79+
4. Run tests using `manage.py`:
80+
81+
```bash
82+
cd test_project
83+
python manage.py test
84+
```
85+
86+
Note that the current test suite generates some expected warnings, which are manually suppressed in the test code.
6487

6588
## Contributors ✨
6689

test_project/test_project/tests.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import logging
2+
from datetime import datetime
13
from unittest.mock import patch
24

3-
from django.test import TestCase
45
from django.core.cache import cache
6+
from django.test import TestCase
57

68
from cache_helper.decorators import cached, cached_class_method, cached_instance_method
79
from cache_helper.exceptions import CacheHelperException, CacheKeyCreationError
810
from cache_helper.interfaces import CacheHelperCacheable
911

10-
from datetime import datetime
11-
12+
DISABLE_LOGGING_BELOW = logging.ERROR
1213
GLOBAL_COUNTER = 200
1314

1415

@@ -112,9 +113,15 @@ def get_product(self):
112113

113114

114115
class CachedInstanceMethodTests(TestCase):
116+
117+
def setUp(self):
118+
logging.disable(DISABLE_LOGGING_BELOW)
119+
super().setUp()
120+
115121
def tearDown(self):
116122
super().tearDown()
117123
cache.clear()
124+
logging.disable(logging.NOTSET)
118125

119126
def test_exception_during_cache_retrieval(self):
120127
incrementer = Incrementer(100)
@@ -272,6 +279,11 @@ def test_invalidate_instance_method(self):
272279

273280

274281
class CachedClassMethodTests(TestCase):
282+
283+
def setUp(self):
284+
logging.disable(DISABLE_LOGGING_BELOW)
285+
super().setUp()
286+
275287
def tearDown(self):
276288
super().tearDown()
277289

@@ -281,6 +293,7 @@ def tearDown(self):
281293
AnotherIncrementer.class_counter = 500
282294

283295
cache.clear()
296+
logging.disable(logging.NOTSET)
284297

285298
def test_exception_during_cache_retrieval(self):
286299
# Hasn't been computed before, so the function actually gets called
@@ -414,12 +427,17 @@ def test_invalidate_class_method(self):
414427

415428

416429
class CachedStaticMethodTests(TestCase):
430+
def setUp(self):
431+
logging.disable(DISABLE_LOGGING_BELOW)
432+
super().setUp()
433+
417434
def tearDown(self):
418435
super().tearDown()
419436

420437
global GLOBAL_COUNTER
421438
GLOBAL_COUNTER = 200
422439
cache.clear()
440+
logging.disable(logging.NOTSET)
423441

424442
def test_exception_during_cache_retrieval(self):
425443
datetime_1 = Incrementer.get_datetime(1)

0 commit comments

Comments
 (0)