1
1
import logging
2
- from collections .abc import Callable , Iterable
2
+ from collections .abc import Callable , Iterable , Iterator
3
3
from pathlib import Path
4
4
5
5
import pytest
6
6
from faker import Faker
7
7
from pydantic import ByteSize , NonNegativeInt
8
- from pytest_simcore .helpers .logging_tools import log_context
8
+
9
+ from .helpers .logging_tools import log_context
9
10
10
11
11
12
@pytest .fixture
@@ -20,8 +21,11 @@ def fake_file_name(tmp_path: Path, faker: Faker) -> Iterable[Path]:
20
21
21
22
22
23
@pytest .fixture
23
- def create_file_of_size (tmp_path : Path , faker : Faker ) -> Callable [[ByteSize ], Path ]:
24
- # NOTE: cleanup is done by tmp_path fixture
24
+ def create_file_of_size (
25
+ tmp_path : Path , faker : Faker
26
+ ) -> Iterator [Callable [[ByteSize ], Path ]]:
27
+ created_files = []
28
+
25
29
def _creator (size : ByteSize , name : str | None = None ) -> Path :
26
30
file : Path = tmp_path / (name or faker .file_name ())
27
31
if not file .parent .exists ():
@@ -32,9 +36,15 @@ def _creator(size: ByteSize, name: str | None = None) -> Path:
32
36
33
37
assert file .exists ()
34
38
assert file .stat ().st_size == size
39
+ created_files .append (file )
35
40
return file
36
41
37
- return _creator
42
+ yield _creator
43
+
44
+ for file in created_files :
45
+ if file .exists ():
46
+ file .unlink ()
47
+ assert not file .exists ()
38
48
39
49
40
50
def _create_random_content (
0 commit comments