lemon-eye-70471
04/30/2024, 8:34 PMlemon-eye-70471
04/30/2024, 8:35 PM# settings.py
import os, random
TESTING = os.environ.get("PANTS_EXECUTION_SLOT") is not None
def get_test_db_name():
suffix = os.getenv("TEST_RUN_ID", str(random.randint(1000, 9999)))
return f"test_database_{suffix}"
DATABASES = {
"default": {
**REST_OF_DB_CONFIG,
"NAME": get_test_db_name() if TESTING else 'app_db',
}
}
# pants.toml
[pytest]
execution_slot_var = "PANTS_EXECUTION_SLOT"
broad-processor-92400
05/01/2024, 4:32 AMPANTS_EXECUTION_SLOT
value directly, rather than a random number.
Although potentially you've already seen it, because your code looks like it might be inspired by it 🙂lemon-eye-70471
05/01/2024, 2:12 PM[pytest]
execution_slot_var = "PANTS_EXECUTION_SLOT"
src/conftest.py
from pytest_django.fixtures import _set_suffix_to_test_databases
from pytest_django.lazy_django import skip_if_no_django
@pytest.fixture(scope="session")
def django_db_modify_db_settings():
skip_if_no_django()
if "PANTS_EXECUTION_SLOT" in os.environ:
_set_suffix_to_test_databases(os.environ["PANTS_EXECUTION_SLOT"])