Skip to content

Commit 093dbd3

Browse files
CopilotBorda
andcommitted
Move common pytest marks to class level for cleaner test code
- Refactored 9 test classes to use class-level pytest.mark decorators - Removed redundant method-level marks when all methods in a class share the same marks - Classes updated: TestStaleCache, TestCacheControl, TestAsyncMethod, TestMaxAge, TestConcurrentAccess, TestNoneHandling, TestAsyncVerboseMode, TestAsyncProcessingEntry, TestAsyncExceptionHandling - Reduces code duplication and makes test structure cleaner - All 30 tests still passing Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
1 parent c81f4a9 commit 093dbd3

1 file changed

Lines changed: 19 additions & 47 deletions

File tree

tests/test_async_core.py

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ async def async_func(x):
7272
# =============================================================================
7373

7474

75+
@pytest.mark.memory
76+
@pytest.mark.asyncio
7577
class TestStaleCache:
7678
"""Tests for stale_after and next_time functionality."""
7779

78-
@pytest.mark.memory
79-
@pytest.mark.asyncio
8080
async def test_recalculates_after_expiry(self):
8181
"""Test that stale_after causes recalculation after expiry."""
8282
call_count = 0
@@ -110,8 +110,6 @@ async def async_func(x):
110110

111111
async_func.clear_cache()
112112

113-
@pytest.mark.memory
114-
@pytest.mark.asyncio
115113
async def test_uses_cache_before_expiry(self):
116114
"""Test that cache is used before stale_after expiry."""
117115
call_count = 0
@@ -139,8 +137,6 @@ async def async_func(x):
139137

140138
async_func.clear_cache()
141139

142-
@pytest.mark.memory
143-
@pytest.mark.asyncio
144140
async def test_next_time_returns_stale_and_updates_background(self):
145141
"""Test next_time=True returns stale value and updates in bg."""
146142
call_count = 0
@@ -186,11 +182,11 @@ async def async_func(x):
186182
# =============================================================================
187183

188184

185+
@pytest.mark.memory
186+
@pytest.mark.asyncio
189187
class TestCacheControl:
190188
"""Tests for cache control parameters - skip_cache & overwrite_cache."""
191189

192-
@pytest.mark.memory
193-
@pytest.mark.asyncio
194190
async def test_skip_cache(self):
195191
"""Test async caching with cachier__skip_cache parameter."""
196192
call_count = 0
@@ -219,8 +215,6 @@ async def async_func(x):
219215

220216
async_func.clear_cache()
221217

222-
@pytest.mark.memory
223-
@pytest.mark.asyncio
224218
async def test_overwrite_cache(self):
225219
"""Test async caching with cachier__overwrite_cache parameter."""
226220
call_count = 0
@@ -255,11 +249,11 @@ async def async_func(x):
255249
# =============================================================================
256250

257251

252+
@pytest.mark.memory
253+
@pytest.mark.asyncio
258254
class TestAsyncMethod:
259255
"""Tests for async caching on class methods."""
260256

261-
@pytest.mark.memory
262-
@pytest.mark.asyncio
263257
async def test_caches_result(self):
264258
"""Test async caching on class methods returns cached result."""
265259

@@ -289,8 +283,6 @@ async def async_method(self, x):
289283

290284
obj1.async_method.clear_cache()
291285

292-
@pytest.mark.memory
293-
@pytest.mark.asyncio
294286
async def test_shares_cache_across_instances(self):
295287
"""Test that async method cache is shared across instances."""
296288

@@ -392,12 +384,12 @@ async def async_func(x, y, z=10):
392384
# =============================================================================
393385

394386

387+
@pytest.mark.memory
388+
@pytest.mark.asyncio
389+
@pytest.mark.maxage
395390
class TestMaxAge:
396391
"""Tests for max_age parameter functionality."""
397392

398-
@pytest.mark.memory
399-
@pytest.mark.asyncio
400-
@pytest.mark.maxage
401393
async def test_recalculates_when_expired(self):
402394
"""Test that max_age causes recalculation when cache is too old."""
403395
call_count = 0
@@ -428,9 +420,6 @@ async def async_func(x):
428420

429421
async_func.clear_cache()
430422

431-
@pytest.mark.memory
432-
@pytest.mark.asyncio
433-
@pytest.mark.maxage
434423
async def test_uses_cache_when_fresh(self):
435424
"""Test that cache is used when within max_age."""
436425
call_count = 0
@@ -458,9 +447,6 @@ async def async_func(x):
458447

459448
async_func.clear_cache()
460449

461-
@pytest.mark.memory
462-
@pytest.mark.asyncio
463-
@pytest.mark.maxage
464450
async def test_negative_max_age_forces_recalculation(self):
465451
"""Test that negative max_age forces recalculation."""
466452
call_count = 0
@@ -493,11 +479,11 @@ async def async_func(x):
493479
# =============================================================================
494480

495481

482+
@pytest.mark.memory
483+
@pytest.mark.asyncio
496484
class TestConcurrentAccess:
497485
"""Tests for concurrent async call behavior."""
498486

499-
@pytest.mark.memory
500-
@pytest.mark.asyncio
501487
async def test_calls_execute_in_parallel(self):
502488
"""Test that concurrent async calls execute in parallel."""
503489
call_count = 0
@@ -524,8 +510,6 @@ async def async_func(x):
524510

525511
async_func.clear_cache()
526512

527-
@pytest.mark.memory
528-
@pytest.mark.asyncio
529513
async def test_consequent_calls_use_cache(self):
530514
"""Test that calls after caching use cached value."""
531515
call_count = 0
@@ -556,8 +540,6 @@ async def async_func(x):
556540

557541
async_func.clear_cache()
558542

559-
@pytest.mark.memory
560-
@pytest.mark.asyncio
561543
async def test_stale_entry_being_processed_with_next_time(self):
562544
"""
563545
Test concurrent calls with stale cache and next_time=True return stale values.
@@ -614,11 +596,11 @@ async def slow_async_func(x):
614596
# =============================================================================
615597

616598

599+
@pytest.mark.memory
600+
@pytest.mark.asyncio
617601
class TestNoneHandling:
618602
"""Tests for allow_none parameter behavior."""
619603

620-
@pytest.mark.memory
621-
@pytest.mark.asyncio
622604
async def test_not_cached_by_default(self):
623605
"""Test that None values are not cached when allow_none=False."""
624606
call_count = 0
@@ -645,8 +627,6 @@ async def async_func(x):
645627

646628
async_func.clear_cache()
647629

648-
@pytest.mark.memory
649-
@pytest.mark.asyncio
650630
async def test_cached_when_allowed(self):
651631
"""Test that None values are cached when allow_none=True."""
652632
call_count = 0
@@ -674,8 +654,6 @@ async def async_func(x):
674654

675655
async_func.clear_cache()
676656

677-
@pytest.mark.memory
678-
@pytest.mark.asyncio
679657
async def test_non_none_cached_with_allow_none_false(self):
680658
"""Test that non-None values are cached even when allow_none=False."""
681659
call_count = 0
@@ -709,11 +687,11 @@ async def async_func(x):
709687
# =============================================================================
710688

711689

690+
@pytest.mark.memory
691+
@pytest.mark.asyncio
712692
class TestAsyncVerboseMode:
713693
"""Tests for verbose_cache parameter with async functions."""
714694

715-
@pytest.mark.memory
716-
@pytest.mark.asyncio
717695
async def test_verbose_cache_parameter(self, capsys):
718696
"""Test verbose_cache parameter prints debug info."""
719697
import warnings
@@ -748,8 +726,6 @@ async def async_func(x):
748726

749727
async_func.clear_cache()
750728

751-
@pytest.mark.memory
752-
@pytest.mark.asyncio
753729
async def test_cachier_verbose_kwarg(self, capsys):
754730
"""Test cachier__verbose keyword argument."""
755731

@@ -865,11 +841,11 @@ async def async_func(x):
865841
async_func.clear_cache()
866842

867843

844+
@pytest.mark.memory
845+
@pytest.mark.asyncio
868846
class TestAsyncProcessingEntry:
869847
"""Tests for entry being processed scenarios with async functions."""
870848

871-
@pytest.mark.memory
872-
@pytest.mark.asyncio
873849
async def test_entry_processing_without_value(self):
874850
"""Test async recalculation when entry is processing but has no value."""
875851
call_count = 0
@@ -897,8 +873,6 @@ async def async_func(x):
897873

898874
async_func.clear_cache()
899875

900-
@pytest.mark.memory
901-
@pytest.mark.asyncio
902876
async def test_stale_entry_processing_recalculates(self):
903877
"""Test that stale entry being processed causes recalculation."""
904878
call_count = 0
@@ -939,11 +913,11 @@ async def async_func(x):
939913
# =============================================================================
940914

941915

916+
@pytest.mark.memory
917+
@pytest.mark.asyncio
942918
class TestAsyncExceptionHandling:
943919
"""Tests for exception handling in async background tasks."""
944920

945-
@pytest.mark.memory
946-
@pytest.mark.asyncio
947921
async def test_function_thread_async_exception_handling(self, capsys):
948922
"""Test that exceptions in background async tasks are caught and printed."""
949923
exception_raised = False
@@ -983,8 +957,6 @@ async def async_func_that_fails(x):
983957

984958
async_func_that_fails.clear_cache()
985959

986-
@pytest.mark.memory
987-
@pytest.mark.asyncio
988960
async def test_entry_size_limit_exceeded_async(self, capsys):
989961
"""Test that exceeding entry_size_limit prints a message."""
990962

0 commit comments

Comments
 (0)