@@ -30,19 +30,21 @@ def test_sync_backend_truthiness():
3030 is truthy.
3131
3232 """
33- spec = TestSpec (source = get_unique_image_file ())
34- file = ImageCacheFile (spec )
35- assert_file_is_truthy (file )
33+ with get_unique_image_file () as source_file :
34+ spec = TestSpec (source = source_file )
35+ file = ImageCacheFile (spec )
36+ assert_file_is_truthy (file )
3637
3738
3839def test_async_backend_falsiness ():
3940 """
4041 Ensure that a cachefile with an asynchronous cache file backend is falsy.
4142
4243 """
43- spec = TestSpec (source = get_unique_image_file ())
44- file = ImageCacheFile (spec , cachefile_backend = DummyAsyncCacheFileBackend ())
45- assert_file_is_falsy (file )
44+ with get_unique_image_file () as source_file :
45+ spec = TestSpec (source = source_file )
46+ file = ImageCacheFile (spec , cachefile_backend = DummyAsyncCacheFileBackend ())
47+ assert_file_is_falsy (file )
4648
4749
4850def test_no_source_error ():
@@ -68,13 +70,14 @@ def test_repr_does_not_send_existence_required():
6870 # import here to apply mock
6971 from imagekit .cachefiles import ImageCacheFile
7072
71- spec = TestSpec (source = get_unique_image_file ())
72- file = ImageCacheFile (
73- spec ,
74- cachefile_backend = DummyAsyncCacheFileBackend ()
75- )
76- file .__repr__ ()
77- assert signal .send .called is False
73+ with get_unique_image_file () as source_file :
74+ spec = TestSpec (source = source_file )
75+ file = ImageCacheFile (
76+ spec ,
77+ cachefile_backend = DummyAsyncCacheFileBackend ()
78+ )
79+ file .__repr__ ()
80+ assert signal .send .called is False
7881
7982
8083def test_memcached_cache_key ():
@@ -118,12 +121,13 @@ def test_lazyfile_stringification():
118121
119122
120123def test_generate_file_already_exists (caplog ):
121- spec = TestSpec (source = get_unique_image_file ())
122- file_1 = ImageCacheFile (spec )
123- file_1 ._generate ()
124- # generate another cache image with the same name
125- file_2 = ImageCacheFile (spec , name = file_1 .name )
126- file_2 ._generate ()
124+ with get_unique_image_file () as source_file :
125+ spec = TestSpec (source = source_file )
126+ file_1 = ImageCacheFile (spec )
127+ file_1 ._generate ()
128+ # generate another cache image with the same name
129+ file_2 = ImageCacheFile (spec , name = file_1 .name )
130+ file_2 ._generate ()
127131
128132 assert len (caplog .records ) == 1
129133 storage , name , actual_name , cachefile_backend = caplog .records [0 ].args
0 commit comments