diff --git a/pytest-embedded-serial-esp/pytest_embedded_serial_esp/serial.py b/pytest-embedded-serial-esp/pytest_embedded_serial_esp/serial.py index 007b81b7..17fdf437 100644 --- a/pytest-embedded-serial-esp/pytest_embedded_serial_esp/serial.py +++ b/pytest-embedded-serial-esp/pytest_embedded_serial_esp/serial.py @@ -13,6 +13,7 @@ class EspSerial(Serial): Attributes: esp: esptool.ESPLoader, will auto upload stub. + stub: esptool.ESPStubLoader, stubbed loader. """ DEFAULT_BAUDRATE = 115200 @@ -58,7 +59,7 @@ def __init__( raise ValueError('Couldn\'t auto detect chip. Please manually specify with "--port"') # stub loader has more functionalities, need to run after calling `run_stub()` - self.stub: esptool.ESPLoader = None # type: ignore + self.stub: esptool.ESPLoader = self.esp.run_stub() if baud > initial_baud: self.esp.change_baud(baud) # change back to the users settings @@ -78,29 +79,21 @@ def _post_init(self): def use_esptool(func): """ - 1. close the port and open the port to kill the `self._forward_io` thread - 2. call `run_stub()` - 3. call to the decorated function, could use `self.stub` as the stubbed loader - 4. call `hard_reset()` - 5. create the `self.forward_io` thread again. + 1. call to the decorated function, could use `self.stub` as the stubbed loader + 2. call `hard_reset()` + 3. create the `self.forward_io` thread again. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): - self.proc.close() - self.proc.open() - settings = self.proc.get_settings() try: with DuplicateStdout(self.pexpect_proc): - self.esp.connect('hard_reset') - self.stub = self.esp.run_stub() ret = func(self, *args, **kwargs) self.stub.hard_reset() finally: self.proc.apply_settings(settings) - self.create_forward_io_thread(self.pexpect_proc) return ret