conftest.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. import logging
  4. import pytest
  5. from _pytest.fixtures import FixtureRequest
  6. from _pytest.monkeypatch import MonkeyPatch
  7. from pytest_embedded_idf.serial import IdfSerial
  8. # This is a custom Serial Class to add the erase_flash functionality
  9. class FlashEncSerial(IdfSerial):
  10. @IdfSerial.use_esptool
  11. def erase_partition(self, partition_name: str) -> None:
  12. if partition_name is None:
  13. logging.error('Invalid arguments')
  14. return
  15. if not self.app.partition_table:
  16. logging.error('Partition table not parsed.')
  17. return
  18. if partition_name in self.app.partition_table:
  19. address = self.app.partition_table[partition_name]['offset']
  20. size = self.app.partition_table[partition_name]['size']
  21. logging.info('Erasing the partition {0} of size {1} at {2}'.format(partition_name, size, address))
  22. self.stub.erase_region(address, size)
  23. else:
  24. logging.error('partition name {0} not found in app partition table'.format(partition_name))
  25. return
  26. @pytest.fixture(scope='module')
  27. def monkeypatch_module(request: FixtureRequest) -> MonkeyPatch:
  28. mp = MonkeyPatch()
  29. request.addfinalizer(mp.undo)
  30. return mp
  31. @pytest.fixture(scope='module', autouse=True)
  32. def replace_dut_class(monkeypatch_module: MonkeyPatch) -> None:
  33. monkeypatch_module.setattr('pytest_embedded_idf.serial.IdfSerial', FlashEncSerial)