forked from p15670423/monkey
BB: Simplify list_machines()
This commit is contained in:
parent
736e779f4c
commit
ea81226c2a
|
@ -1,9 +1,8 @@
|
||||||
|
from typing import Collection, Dict, Mapping, Set
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from envs.monkey_zoo.blackbox.gcp_test_machine_list import (
|
from envs.monkey_zoo.blackbox.gcp_test_machine_list import GCP_SINGLE_TEST_LIST
|
||||||
GCP_SINGLE_TEST_LIST,
|
|
||||||
GCP_TEST_MACHINE_LIST,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
|
@ -38,30 +37,17 @@ def no_gcp(request):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def list_machines(request):
|
def list_machines(request: pytest.FixtureRequest) -> Mapping[str, Collection[str]]:
|
||||||
enabled_tests = [test.name for test in request.node.items]
|
machines_to_start: Dict[str, Set[str]] = {}
|
||||||
|
|
||||||
if len(enabled_tests) == len(GCP_SINGLE_TEST_LIST.keys()):
|
enabled_tests = (test.name for test in request.node.items)
|
||||||
return GCP_TEST_MACHINE_LIST
|
machines_for_enabled_tests = (GCP_SINGLE_TEST_LIST[test] for test in enabled_tests)
|
||||||
|
|
||||||
try:
|
for machine_dict in machines_for_enabled_tests:
|
||||||
list_machines_to_start = [GCP_SINGLE_TEST_LIST[test] for test in enabled_tests]
|
for zone, machines in machine_dict.items():
|
||||||
|
machines_to_start.setdefault(zone, set()).update(machines)
|
||||||
|
|
||||||
if len(list_machines_to_start) == 1:
|
return machines_to_start
|
||||||
return list_machines_to_start[0]
|
|
||||||
|
|
||||||
single_machine_list = {}
|
|
||||||
|
|
||||||
for machine_dict in list_machines_to_start:
|
|
||||||
for zone, machines in machine_dict.items():
|
|
||||||
for machine in machines:
|
|
||||||
if machine not in single_machine_list[zone]:
|
|
||||||
single_machine_list[zone].append(machine)
|
|
||||||
|
|
||||||
except KeyError:
|
|
||||||
return GCP_TEST_MACHINE_LIST
|
|
||||||
|
|
||||||
return single_machine_list
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_runtest_setup(item):
|
def pytest_runtest_setup(item):
|
||||||
|
|
Loading…
Reference in New Issue