Skip to content

Commit a5d71b3

Browse files
committed
Capture image in pytest
1 parent 706aaf6 commit a5d71b3

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

.github/workflows/build-run-applications.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ jobs:
205205
- name: Run apps
206206
run: |
207207
pytest --suppress-no-test-exit-code --ignore-glob '*/managed_components/*' --ignore=.github --junit-xml=${{ env.TEST_RESULT_FILE }} --target=${{ matrix.runner.target }} -m ${{ matrix.runner.marker }} --build-dir=build_${{ matrix.runner.runs-on }} ${{ env.PYTEST_BENCHMARK_IGNORE }}
208-
python .github/ci/runner_camera.py
209208
- name: Upload test results
210209
uses: actions/upload-artifact@v4
211210
if: always()

examples/display/pytest_display.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
1+
# SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: CC0-1.0
33

44
import pytest
55
from pytest_embedded import Dut
6+
from pytest_helpers import bsp_test_image
7+
import sys
8+
import os
9+
10+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
611

712

813
@pytest.mark.esp_box_3
@@ -20,6 +25,8 @@
2025
@pytest.mark.m5stack_core_s3
2126
@pytest.mark.m5stack_core_s3_se
2227
@pytest.mark.m5_atom_s3
23-
def test_display_example(dut: Dut) -> None:
28+
def test_display_example(dut: Dut, request) -> None:
29+
board = request.node.callspec.id
2430
dut.expect_exact('example: Display LVGL animation')
2531
dut.expect_exact('main_task: Returned from app_main()')
32+
bsp_test_image(board, "display", "")

examples/pytest_helpers.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: Apache-2.0
3+
import cv2
4+
5+
6+
def bsp_capture_image(image_path):
7+
# Return video from the first webcam on your computer.
8+
cap = cv2.VideoCapture(0)
9+
# reads frames from a camera
10+
# ret checks return at each frame
11+
ret, frame = cap.read()
12+
if ret:
13+
# TODO: Change size image
14+
# TODO: Crop image
15+
16+
# Save image
17+
cv2.imwrite(image_path, frame)
18+
print(f"Image saved {image_path}")
19+
else:
20+
print("Cannot save image.")
21+
22+
# Close the window / Release webcam
23+
cap.release()
24+
25+
26+
def bsp_test_image(board, example, expectation):
27+
image_file = f"snapshot_{example}_{board}.jpg"
28+
bsp_capture_image(image_file)

0 commit comments

Comments
 (0)