2024-06-11 13:36:20 +02:00
|
|
|
import os
|
2024-12-16 12:38:24 +02:00
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from typing import List
|
2025-02-03 13:24:08 +02:00
|
|
|
import pytest
|
2024-12-12 13:45:21 +01:00
|
|
|
|
2024-06-11 13:36:20 +02:00
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption(
|
2024-12-12 13:45:21 +01:00
|
|
|
"--status_backend_url",
|
2024-06-11 13:36:20 +02:00
|
|
|
action="store",
|
|
|
|
help="",
|
2024-12-12 13:45:21 +01:00
|
|
|
default=None,
|
2024-06-11 13:36:20 +02:00
|
|
|
)
|
2024-09-16 10:23:57 +02:00
|
|
|
parser.addoption(
|
2024-12-12 13:45:21 +01:00
|
|
|
"--anvil_url",
|
2024-09-16 10:23:57 +02:00
|
|
|
action="store",
|
|
|
|
help="",
|
2024-12-12 13:45:21 +01:00
|
|
|
default="http://0.0.0.0:8545",
|
2024-09-16 10:23:57 +02:00
|
|
|
)
|
2024-10-07 17:40:18 +02:00
|
|
|
parser.addoption(
|
2024-12-12 13:45:21 +01:00
|
|
|
"--password",
|
2024-10-07 17:40:18 +02:00
|
|
|
action="store",
|
|
|
|
help="",
|
2024-12-12 13:45:21 +01:00
|
|
|
default="Strong12345",
|
2024-10-07 17:40:18 +02:00
|
|
|
)
|
2024-09-25 14:27:04 +02:00
|
|
|
parser.addoption(
|
2024-12-12 13:45:21 +01:00
|
|
|
"--docker_project_name",
|
2024-09-25 14:27:04 +02:00
|
|
|
action="store",
|
|
|
|
help="",
|
2024-12-12 13:45:21 +01:00
|
|
|
default="tests-functional",
|
2024-09-25 14:27:04 +02:00
|
|
|
)
|
2024-06-11 13:36:20 +02:00
|
|
|
parser.addoption(
|
2024-12-12 13:45:21 +01:00
|
|
|
"--codecov_dir",
|
2024-06-11 13:36:20 +02:00
|
|
|
action="store",
|
|
|
|
help="",
|
2024-12-12 13:45:21 +01:00
|
|
|
default=None,
|
|
|
|
)
|
|
|
|
parser.addoption(
|
|
|
|
"--user_dir",
|
|
|
|
action="store",
|
|
|
|
help="",
|
|
|
|
default=None,
|
2024-06-11 13:36:20 +02:00
|
|
|
)
|
|
|
|
|
2024-12-16 12:38:24 +02:00
|
|
|
|
2024-06-11 13:36:20 +02:00
|
|
|
@dataclass
|
|
|
|
class Option:
|
2024-12-16 12:38:24 +02:00
|
|
|
status_backend_port_range: List[int] = field(default_factory=list)
|
|
|
|
status_backend_containers: List[str] = field(default_factory=list)
|
|
|
|
base_dir: str = ""
|
2024-06-11 13:36:20 +02:00
|
|
|
|
2024-10-11 11:08:39 +03:00
|
|
|
|
2024-06-11 13:36:20 +02:00
|
|
|
option = Option()
|
|
|
|
|
2024-10-11 11:08:39 +03:00
|
|
|
|
2024-06-11 13:36:20 +02:00
|
|
|
def pytest_configure(config):
|
|
|
|
global option
|
|
|
|
option = config.option
|
2024-12-12 13:45:21 +01:00
|
|
|
|
2024-12-16 12:38:24 +02:00
|
|
|
executor_number = int(os.getenv("EXECUTOR_NUMBER", 5))
|
2024-12-12 13:45:21 +01:00
|
|
|
base_port = 7000
|
|
|
|
range_size = 100
|
2025-02-03 13:24:08 +02:00
|
|
|
max_port = 65535
|
|
|
|
min_port = 1024
|
2024-12-12 13:45:21 +01:00
|
|
|
|
|
|
|
start_port = base_port + (executor_number * range_size)
|
2025-02-03 13:24:08 +02:00
|
|
|
end_port = start_port + 20000
|
|
|
|
|
|
|
|
# Ensure generated ports are within the valid range
|
|
|
|
if start_port < min_port or end_port > max_port:
|
|
|
|
raise ValueError(f"Generated port range ({start_port}-{end_port}) is outside the allowed range ({min_port}-{max_port}).")
|
2024-12-12 13:45:21 +01:00
|
|
|
|
2025-02-03 13:24:08 +02:00
|
|
|
option.status_backend_port_range = list(range(start_port, end_port))
|
2024-12-12 13:45:21 +01:00
|
|
|
option.status_backend_containers = []
|
|
|
|
|
2024-06-11 13:36:20 +02:00
|
|
|
option.base_dir = os.path.dirname(os.path.abspath(__file__))
|
2024-12-12 13:45:21 +01:00
|
|
|
|
2024-12-16 12:38:24 +02:00
|
|
|
|
2025-02-03 13:24:08 +02:00
|
|
|
@pytest.fixture(scope="function", autouse=True)
|
|
|
|
def close_status_backend_containers(request):
|
|
|
|
yield
|
|
|
|
if hasattr(request.node.instance, "reuse_container"):
|
|
|
|
return
|
|
|
|
for container in option.status_backend_containers:
|
|
|
|
container.kill() # type: ignore
|