11import logging
2- from collections .abc import Callable , Iterable
2+ from collections .abc import Callable , Iterable , Iterator
33from pathlib import Path
44
55import pytest
66from faker import Faker
77from pydantic import ByteSize , NonNegativeInt
8- from pytest_simcore .helpers .logging_tools import log_context
8+
9+ from .helpers .logging_tools import log_context
910
1011
1112@pytest .fixture
@@ -20,8 +21,11 @@ def fake_file_name(tmp_path: Path, faker: Faker) -> Iterable[Path]:
2021
2122
2223@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+
2529 def _creator (size : ByteSize , name : str | None = None ) -> Path :
2630 file : Path = tmp_path / (name or faker .file_name ())
2731 if not file .parent .exists ():
@@ -32,9 +36,15 @@ def _creator(size: ByteSize, name: str | None = None) -> Path:
3236
3337 assert file .exists ()
3438 assert file .stat ().st_size == size
39+ created_files .append (file )
3540 return file
3641
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 ()
3848
3949
4050def _create_random_content (
0 commit comments