Skip to content

Commit 067e133

Browse files
committed
improvements according to feedback @pcrespov
1 parent eb7e6d0 commit 067e133

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

clients/python/test/e2e/conftest.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from packaging.version import Version
1919
from pydantic import ByteSize
2020
from typing import NamedTuple, Final
21-
from tempfile import TemporaryDirectory
2221

2322
try:
2423
from osparc._settings import ConfigurationEnvVars
@@ -113,8 +112,8 @@ def api_client() -> Iterable[osparc.ApiClient]:
113112

114113

115114
@pytest.fixture(scope="session")
116-
def files_api(api_client: osparc.ApiClient) -> Iterable[osparc.FilesApi]:
117-
yield osparc.FilesApi(api_client=api_client)
115+
def files_api(api_client: osparc.ApiClient) -> osparc.FilesApi:
116+
return osparc.FilesApi(api_client=api_client)
118117

119118

120119
@pytest.fixture
@@ -144,25 +143,28 @@ class ServerFile(NamedTuple):
144143

145144

146145
@pytest.fixture(scope="session")
147-
def large_server_file(files_api: osparc.FilesApi) -> Iterable[ServerFile]:
146+
def large_server_file(
147+
files_api: osparc.FilesApi, tmp_path_factory
148+
) -> Iterable[ServerFile]:
148149
_file_size: Final[ByteSize] = ByteSize(1 * _GB)
149-
with TemporaryDirectory() as tmp_path:
150-
tmp_path = Path(tmp_path)
151-
tmp_file = tmp_path / "large_test_file.txt"
152-
ss: random.SeedSequence = random.SeedSequence()
153-
logging.info("Entropy used to generate random file: %s", f"{ss.entropy}")
154-
rng: random.Generator = random.default_rng(ss)
155-
tmp_file.write_bytes(rng.bytes(1000))
156-
with open(tmp_file, "wb") as f:
157-
f.truncate(_file_size)
158-
assert (
159-
tmp_file.stat().st_size == _file_size
160-
), f"Could not create file of size: {_file_size}"
161-
uploaded_file: osparc.File = files_api.upload_file(tmp_file)
162-
163-
yield ServerFile(local_file=tmp_file, server_file=uploaded_file)
164-
165-
files_api.delete_file(uploaded_file.id)
150+
tmp_file = (
151+
tmp_path_factory.mktemp(basename=large_server_file.__name__)
152+
/ "large_test_file.txt"
153+
)
154+
ss: random.SeedSequence = random.SeedSequence()
155+
logging.info("Entropy used to generate random file: %s", f"{ss.entropy}")
156+
rng: random.Generator = random.default_rng(ss)
157+
tmp_file.write_bytes(rng.bytes(1000))
158+
with open(tmp_file, "wb") as f:
159+
f.truncate(_file_size)
160+
assert (
161+
tmp_file.stat().st_size == _file_size
162+
), f"Could not create file of size: {_file_size}"
163+
uploaded_file: osparc.File = files_api.upload_file(tmp_file)
164+
165+
yield ServerFile(local_file=tmp_file, server_file=uploaded_file)
166+
167+
files_api.delete_file(uploaded_file.id)
166168

167169

168170
@pytest.fixture

0 commit comments

Comments
 (0)