diff --git a/tests/conftest.py b/tests/conftest.py index b5cdc069f..3705cd7b3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,27 @@ # SPDX-License-Identifier: Apache-2.0 -# Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest +# Copyright Pionix GmbH and Contributors to EVerest + +from pathlib import Path +import pytest -import os def pytest_addoption(parser): parser.addoption("--everest-prefix", action="store", default="../build/dist", help="everest prefix path; default = '../build/dist'") + + +def pytest_configure(config): + everest_prefix = config.getoption('--everest-prefix') + everest_config_path = Path(everest_prefix) / 'etc/everest' + everest_configs = [path for path in everest_config_path.iterdir( + ) if path.name.startswith('config-') and path.name.endswith('yaml')] + pytest.everest_configs = {} + pytest.everest_configs['params'] = [] + pytest.everest_configs['ids'] = [] + for config_path in everest_configs: + config_id = config_path.stem + if config_id == 'config-sil-gen-pm': + # skip + continue + pytest.everest_configs['params'].append(config_path) + pytest.everest_configs['ids'].append(config_id) diff --git a/tests/core_tests/config_tests.py b/tests/core_tests/config_tests.py index 8f6a4f17d..5dbca3184 100644 --- a/tests/core_tests/config_tests.py +++ b/tests/core_tests/config_tests.py @@ -19,46 +19,12 @@ EverestConfigAdjustmentVisitor -@pytest.mark.everest_core_config('config-example.yaml') -@pytest.mark.asyncio -async def test_start_config_example(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_example <<<<<<<<<") - everest_core.start() - - -@pytest.mark.everest_core_config('config-sil-dc-sae-v2g.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_dc_sae_v2g(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil_dc_sae_v2g <<<<<<<<<") - everest_core.start() - - -@pytest.mark.everest_core_config('config-sil-dc-sae-v2h.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_dc_sae_v2h(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil_dc_sae_v2h <<<<<<<<<") - everest_core.start() - - -@pytest.mark.everest_core_config('config-sil-dc.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_dc(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil_dc <<<<<<<<<") - everest_core.start() - - -@pytest.mark.everest_core_config('config-sil-energy-management.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_energy_management(everest_core: EverestCore): - logging.info(">>>>>>>>> test_config_sil_energy_management <<<<<<<<<") - everest_core.start() - - class EverestCoreConfigSilGenPmConfigurationVisitor(EverestConfigAdjustmentVisitor): def __init__(self): self.temporary_directory = mkdtemp() self.serial_port_0, self.serial_port_1 = pty.openpty() - self.serial_port_0_name = os.ttyname(self.serial_port_0) # FIXME: cleanup socket after test + # FIXME: cleanup socket after test + self.serial_port_0_name = os.ttyname(self.serial_port_0) def adjust_everest_configuration(self, everest_config: Dict): adjusted_config = deepcopy(everest_config) @@ -77,51 +43,19 @@ async def test_start_config_sil_gen_pm(everest_core: EverestCore): everest_core.start() -@pytest.mark.everest_core_config('config-sil-ocpp-custom-extension.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_ocpp_custom_extension(everest_core: EverestCore): - logging.info( - ">>>>>>>>> test_start_config_sil_ocpp_custom_extension <<<<<<<<<") - everest_core.start() +class TestConfigsInDirectory: + @pytest.fixture(params=pytest.everest_configs['params'], ids=pytest.everest_configs['ids']) + def core_config(self, request) -> EverestEnvironmentCoreConfiguration: + everest_prefix = Path(request.config.getoption("--everest-prefix")) + everest_config_path = request.param -@pytest.mark.everest_core_config('config-sil-ocpp-pnc.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_ocpp_pnc(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil_ocpp_pnc <<<<<<<<<") - everest_core.start() - - -@pytest.mark.everest_core_config('config-sil-ocpp.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_ocpp(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil_ocpp <<<<<<<<<") - everest_core.start() - - -@pytest.mark.everest_core_config('config-sil-ocpp201.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_ocpp201(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil_ocpp201 <<<<<<<<<") - everest_core.start() - + return EverestEnvironmentCoreConfiguration( + everest_core_path=everest_prefix, + template_everest_config_path=everest_config_path, + ) -@pytest.mark.everest_core_config('config-sil-two-evse-dc.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_two_evse_dc(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil_two_evse_dc <<<<<<<<<") - everest_core.start() - - -@pytest.mark.everest_core_config('config-sil-two-evse.yaml') -@pytest.mark.asyncio -async def test_start_config_sil_two_evse(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil_two_evse <<<<<<<<<") - everest_core.start() - - -@pytest.mark.everest_core_config('config-sil.yaml') -@pytest.mark.asyncio -async def test_start_config_sil(everest_core: EverestCore): - logging.info(">>>>>>>>> test_start_config_sil <<<<<<<<<") - everest_core.start() + @pytest.mark.asyncio + async def test_config(self, everest_core: EverestCore): + logging.info(">>>>>>>>> test_config <<<<<<<<<") + everest_core.start() diff --git a/tests/pytest.ini b/tests/pytest.ini index 7204f927a..c6aea78b6 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -4,3 +4,4 @@ log_level=debug asyncio_mode=strict markers = everest_core_config: marks tests using a specific config (deselect with '-m "not everest_core_config"') + everest_config_adaptions: modify config for a specific testcase