From b7b00a51ab5bd6503b326254bb2391ad13023720 Mon Sep 17 00:00:00 2001 From: yiwenxiu Date: Thu, 21 May 2026 12:56:36 +0800 Subject: [PATCH] ci: add tear down for openthread ci case --- examples/openthread/pytest_otbr.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/examples/openthread/pytest_otbr.py b/examples/openthread/pytest_otbr.py index 26aca26040d..9f4ae0722e9 100644 --- a/examples/openthread/pytest_otbr.py +++ b/examples/openthread/pytest_otbr.py @@ -11,6 +11,7 @@ import subprocess import sys import threading import time +from collections.abc import Generator sys.path.append(os.path.dirname(os.path.abspath(__file__))) import ot_ci_function as ocf @@ -105,6 +106,25 @@ ESPPORT4 = os.getenv('ESPPORT4') PORT_MAPPING = {'ESPPORT1': 'esp32h2', 'ESPPORT2': 'esp32s3', 'ESPPORT3': 'esp32c6', 'ESPPORT4': 'esp32c5'} +@pytest.fixture(scope='module', autouse=True) +def erase_flash_after_all_cases() -> Generator[None, None, None]: + yield + + serial_ports = list(dict.fromkeys(filter(None, map(os.getenv, PORT_MAPPING)))) + failed_ports = [] + for serial_port in serial_ports: + command = ['python', '-m', 'esptool', '--port', serial_port, 'erase_flash'] + logging.info('Erasing flash on %s: %s', serial_port, ' '.join(command)) + result = subprocess.run(command, capture_output=True, text=True) + logging.info('Erase flash stdout on %s:\n%s', serial_port, result.stdout) + if result.stderr: + logging.info('Erase flash stderr on %s:\n%s', serial_port, result.stderr) + if result.returncode != 0: + failed_ports.append(serial_port) + + assert not failed_ports, f'Failed to erase flash on ports: {failed_ports}' + + # Case 1: Thread network formation and attaching @pytest.mark.openthread_br @pytest.mark.flaky(reruns=1, reruns_delay=5)