@@ -136,21 +136,23 @@ pytest -n 4
136136import pytest
137137from cachier import cachier
138138
139+
139140def test_basic_caching ():
140141 """ Test basic caching functionality."""
142+
141143 # Define a cached function local to this test
142144 @cachier ()
143145 def expensive_computation (x ):
144- return x ** 2
145-
146+ return x** 2
147+
146148 # First call - should compute
147149 result1 = expensive_computation(5 )
148150 assert result1 == 25
149-
151+
150152 # Second call - should return from cache
151153 result2 = expensive_computation(5 )
152154 assert result2 == 25
153-
155+
154156 # Clear cache for cleanup
155157 expensive_computation.clear_cache()
156158```
@@ -162,11 +164,11 @@ def test_basic_caching():
162164def test_mongo_specific_feature ():
163165 """ Test MongoDB-specific functionality."""
164166 from tests.test_mongo_core import _test_mongetter
165-
167+
166168 @cachier (mongetter = _test_mongetter)
167169 def mongo_cached_func (x ):
168170 return x * 2
169-
171+
170172 # Test implementation
171173 assert mongo_cached_func(5 ) == 10
172174```
@@ -180,6 +182,7 @@ def test_mongo_specific_feature():
180182#### Why This Matters
181183
182184Cachier identifies cached functions by their full module path and function name. When tests share decorated functions:
185+
183186- Cache entries can conflict between tests
184187- Parallel test execution may fail unpredictably
185188- Test results become non-deterministic
@@ -191,14 +194,15 @@ def test_feature_one():
191194 @cachier ()
192195 def compute_one (x ): # Unique to this test
193196 return x * 2
194-
197+
195198 assert compute_one(5 ) == 10
196199
200+
197201def test_feature_two ():
198202 @cachier ()
199203 def compute_two (x ): # Different function for different test
200204 return x * 2
201-
205+
202206 assert compute_two(5 ) == 10
203207```
204208
@@ -210,9 +214,11 @@ def test_feature_two():
210214def shared_compute (x ): # Shared between tests
211215 return x * 2
212216
217+
213218def test_feature_one ():
214219 assert shared_compute(5 ) == 10 # May conflict with test_feature_two
215220
221+
216222def test_feature_two ():
217223 assert shared_compute(5 ) == 10 # May conflict with test_feature_one
218224```
@@ -239,10 +245,11 @@ def test_feature_two():
239245@pytest.mark.mongo
240246def test_mongo_feature ():
241247 """ Test with MongoDB backend."""
248+
242249 @cachier (mongetter = _test_mongetter, wait_for_calc_timeout = 2 )
243250 def mongo_func (x ):
244251 return x
245-
252+
246253 # MongoDB-specific assertions
247254 assert mongo_func.get_cache_mongetter() is not None
248255```
@@ -253,10 +260,11 @@ def test_mongo_feature():
253260@pytest.mark.redis
254261def test_redis_feature ():
255262 """ Test with Redis backend."""
256- @cachier (backend = ' redis' , redis_client = _test_redis_client)
263+
264+ @cachier (backend = " redis" , redis_client = _test_redis_client)
257265 def redis_func (x ):
258266 return x
259-
267+
260268 # Redis-specific testing
261269 assert redis_func(5 ) == 5
262270```
@@ -267,10 +275,11 @@ def test_redis_feature():
267275@pytest.mark.sql
268276def test_sql_feature ():
269277 """ Test with SQL backend."""
270- @cachier (backend = ' sql' , sql_engine = test_engine)
278+
279+ @cachier (backend = " sql" , sql_engine = test_engine)
271280 def sql_func (x ):
272281 return x
273-
282+
274283 # SQL-specific testing
275284 assert sql_func(5 ) == 5
276285```
@@ -281,10 +290,11 @@ def test_sql_feature():
281290@pytest.mark.memory
282291def test_memory_feature ():
283292 """ Test with memory backend."""
284- @cachier (backend = ' memory' )
293+
294+ @cachier (backend = " memory" )
285295 def memory_func (x ):
286296 return x
287-
297+
288298 # Memory-specific testing
289299 assert memory_func(5 ) == 5
290300```
@@ -345,50 +355,61 @@ pytest -m sql
345355### Common Issues
346356
3473571 . ** Import Errors** : Install backend-specific requirements
358+
348359 ``` bash
349360 pip install -r tests/redis_requirements.txt
350361 ```
351362
3523632 . ** Docker Not Running** : Start Docker Desktop or daemon
364+
353365 ``` bash
354366 docker ps # Check if Docker is running
355367 ```
356368
3573693 . ** Port Conflicts** : Stop conflicting services
370+
358371 ``` bash
359372 docker stop cachier-test-mongo cachier-test-redis cachier-test-postgres
360373 ```
361374
3623754 . ** Flaky Tests** : Usually due to timing issues
376+
363377 - Increase timeouts
364378 - Add proper waits
365379 - Check for race conditions
366380
3673815 . ** Cache Conflicts** : Ensure function isolation
382+
368383 - Don't share decorated functions
369384 - Clear cache after tests
370385 - Use unique function names
371386
372387### Debugging Tips
373388
374- 1 . ** Run Single Test** :
389+ 1 . ** Run Single Test** :
390+
375391 ``` bash
376392 pytest -k test_name -v
377393 ```
378394
379- 2 . ** Disable Parallel** :
395+ 2 . ** Disable Parallel** :
396+
380397 ``` bash
381398 pytest -n 1
382399 ```
383400
3844013 . ** Check Logs** :
402+
385403 ``` bash
386404 docker logs cachier-test-mongo
387405 ```
388406
3894074 . ** Interactive Debugging** :
408+
390409 ``` python
391- import pdb; pdb.set_trace()
410+ import pdb
411+
412+ pdb.set_trace()
392413 ```
393414
394415### Performance Considerations
@@ -427,4 +448,4 @@ When adding new tests:
427448- Check existing tests for examples
428449- Review the main README.rst
429450- Open an issue on GitHub
430- - Contact maintainers listed in README.rst
451+ - Contact maintainers listed in README.rst
0 commit comments