1
0
mirror of https://github.com/home-assistant/operating-system.git synced 2025-12-20 02:18:37 +00:00
Files
operating-system/tests/conftest.py
Jan Čermák 39778e882a Add test suite for Supervisor tests (#2880)
* Add test suite for Supervisor tests

* test_supervisor_is_updated should depend on test_update_supervisor

Co-authored-by: Stefan Agner <stefan@agner.ch>

---------

Co-authored-by: Stefan Agner <stefan@agner.ch>
2023-10-31 10:12:10 +01:00

51 lines
1.3 KiB
Python

import json
import logging
import os
from labgrid.driver import ShellDriver
import pytest
logger = logging.getLogger(__name__)
@pytest.fixture(autouse=True, scope="module")
def restart_qemu(strategy):
"""Use fresh QEMU instance for each module."""
if strategy.status.name == "shell":
logger.info("Restarting QEMU before %s module tests.", strategy.target.name)
strategy.transition("off")
strategy.transition("shell")
@pytest.hookimpl
def pytest_runtest_setup(item):
log_dir = item.config.option.lg_log
if not log_dir:
return
logging_plugin = item.config.pluginmanager.get_plugin("logging-plugin")
log_name = item.nodeid.replace(".py::", "/")
logging_plugin.set_log_path(os.path.join(log_dir, f"{log_name}.log"))
@pytest.fixture
def shell(target, strategy) -> ShellDriver:
"""Fixture for accessing shell."""
strategy.transition("shell")
shell = target.get_driver("ShellDriver")
return shell
@pytest.fixture
def shell_json(target, strategy) -> callable:
"""Fixture for running CLI commands returning JSON string as output."""
strategy.transition("shell")
shell = target.get_driver("ShellDriver")
def get_json_response(command, *, timeout=60) -> dict:
return json.loads("\n".join(shell.run_check(command, timeout=timeout)))
return get_json_response