{"library":"pytest-embedded-idf","title":"pytest-embedded-idf Integration for ESP-IDF","description":"pytest-embedded-idf is a pytest plugin that extends pytest-embedded to provide a robust testing framework specifically designed for ESP-IDF based firmware. It streamlines the process of building, flashing, and testing applications on Espressif hardware, integrating directly with `idf.py` tools. The current version is 2.7.0, and it follows the release cadence of `pytest-embedded` and ESP-IDF updates.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pytest-embedded-idf"],"cli":null},"imports":["from pytest_embedded_idf.dut import IdfDut"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"# Save this as 'test_hello.py' in your ESP-IDF project directory (e.g., esp-idf/examples/get-started/hello_world)\n# Requirements:\n# 1. An ESP-IDF project directory.\n# 2. ESP-IDF environment variable IDF_PATH correctly set.\n# 3. A compatible Espressif development board connected via USB.\n# 4. pip install pytest pytest-embedded pytest-embedded-idf\n\nimport pytest\nfrom pytest_embedded_idf.dut import IdfDut\nimport os\n\n# Example: Mark the test to run on an ESP32 target.\n# You can change this to esp32s2, esp32s3, esp32c3, esp32c6, etc.,\n# depending on your target and --target option if specified.\n@pytest.mark.esp32\ndef test_hello_world_output(dut: IdfDut):\n    \"\"\"\n    Tests that the ESP-IDF 'hello_world' example prints the expected output.\n    The 'dut' fixture automatically handles building, flashing, and connecting.\n    \"\"\"\n    print(f\"\\nConnected DUT target: {dut.target}\")\n    print(f\"DUT COM Port: {dut.serial.port}\")\n    print(f\"Application path: {dut.app.path}\")\n\n    # Expect 'Hello world!' from the device's serial output\n    dut.expect(r'Hello world!')\n    print(\"Successfully received 'Hello world!' from DUT.\")\n\n    # Example: Send a command (if your application supports it)\n    # dut.write('get_heap')\n    # dut.expect(r'Free heap: \\d+ bytes')\n","lang":"python","description":"This quickstart demonstrates a basic `pytest-embedded-idf` test. It uses the `IdfDut` fixture to interact with an ESP-IDF device. The test asserts that the device outputs 'Hello world!'. Ensure your ESP-IDF environment (`IDF_PATH`) is set up and an ESP device is connected. Run with `pytest` from your ESP-IDF project directory.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}