Skip to content

Commit 29df0b9

Browse files
committed
ensure created files are deleted right away
1 parent 08f5490 commit 29df0b9

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

packages/pytest-simcore/src/pytest_simcore/file_extra.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import logging
2-
from collections.abc import Callable, Iterable
2+
from collections.abc import Callable, Iterable, Iterator
33
from pathlib import Path
44

55
import pytest
66
from faker import Faker
77
from 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

4050
def _create_random_content(

0 commit comments

Comments
 (0)