Files
signoz/tests/e2e/bootstrap/setup.py
Ashwin Bhatkal 5363dc6b0e test: new playwright project to seed data (#11271)
* test: new playwright project to seed data

* test: add teardown bits

* test: move from fixtures to seeder

* test: format file

* test: format file + update lockfile
2026-05-14 08:37:40 +00:00

57 lines
2.1 KiB
Python

import os
from pathlib import Path
import pytest
import requests
from fixtures import types
from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD
def _env_file(pytestconfig: pytest.Config) -> Path:
override = os.environ.get("SIGNOZ_E2E_ENV_FILE")
if override:
return Path(override)
return pytestconfig.rootpath / "e2e" / ".env.local"
def test_setup(
signoz: types.SigNoz,
create_user_admin: types.Operation, # pylint: disable=unused-argument
apply_license: types.Operation, # pylint: disable=unused-argument
seeder: types.TestContainerDocker,
pytestconfig: pytest.Config,
) -> None:
"""Bring the backend up and write e2e coordinates to .env.local."""
host_cfg = signoz.self.host_configs["8080"]
seeder_cfg = seeder.host_configs["8080"]
out = _env_file(pytestconfig)
out.parent.mkdir(parents=True, exist_ok=True)
with out.open("w") as f:
f.write("# Generated by tests/e2e/bootstrap/setup.py — do not edit.\n")
f.write(f"SIGNOZ_E2E_BASE_URL={host_cfg.base()}\n")
f.write(f"SIGNOZ_E2E_USERNAME={USER_ADMIN_EMAIL}\n")
f.write(f"SIGNOZ_E2E_PASSWORD={USER_ADMIN_PASSWORD}\n")
f.write(f"SIGNOZ_E2E_SEEDER_URL={seeder_cfg.base()}\n")
def test_teardown(
signoz: types.SigNoz, # pylint: disable=unused-argument
create_user_admin: types.Operation, # pylint: disable=unused-argument
apply_license: types.Operation, # pylint: disable=unused-argument
seeder: types.TestContainerDocker, # pylint: disable=unused-argument
pytestconfig: pytest.Config,
) -> None:
"""Truncate seeded telemetry; containers come down via fixture
dependency under `--teardown`."""
cached = pytestconfig.cache.get("seeder", None)
if not cached:
return
restored = types.TestContainerDocker.from_cache(cached)
base = restored.host_configs["8080"].base().rstrip("/")
for signal in ("metrics", "traces", "logs"):
try:
requests.delete(f"{base}/telemetry/{signal}", timeout=30).raise_for_status()
except Exception as e: # pylint: disable=broad-exception-caught
print(f"seeder DELETE /telemetry/{signal} failed: {e}")