From 051f0b964e56951f7e163e5aaa0d787eab175963 Mon Sep 17 00:00:00 2001 From: bronsen <kontakt+gitcommit@nrrd.de> Date: Sat, 15 Mar 2025 22:25:13 +0100 Subject: [PATCH] [test] add new fixture to generate random strings of given length --- collector/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/collector/conftest.py b/collector/conftest.py index a925f11..6266efd 100644 --- a/collector/conftest.py +++ b/collector/conftest.py @@ -1,3 +1,7 @@ +import random +import string +from typing import Callable + import pytest from django.test import Client @@ -10,3 +14,12 @@ def enable_db_access_for_all_tests(db): @pytest.fixture(scope="session", name="session") def fixture_longlived_client() -> Client: return Client() + +@pytest.fixture(name="random_name") +def fixture_random_name_generator() -> Callable[[int], str]: + def name_generator(length: int = 7) -> str: + name = "".join(random.choices(string.ascii_letters, k=length)) + return name + + return name_generator +