Skip to content

Commit

Permalink
ci(test_esptool): Migrate tests from unittest to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
radimkarnis committed Oct 25, 2022
1 parent 40e6afd commit 1d18196
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 345 deletions.
19 changes: 10 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ check_stub_build:
variables:
PYTHONPATH: "$PYTHONPATH:${CI_PROJECT_DIR}/test"
COVERAGE_PROCESS_START: "${CI_PROJECT_DIR}/test/.covconf"
PYTEST_ADDOPTS: "-sv --junitxml=test/report.xml --color=yes"
before_script:
- pip install -e .[dev] --prefer-binary
artifacts:
Expand All @@ -202,7 +203,7 @@ target_esptool_test_esp8266:
tags:
- esptool_esp8266_target
script:
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP8266 esp8266 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP8266 --chip esp8266 --baud 115200

# ESP32
target_esptool_test_esp32:
Expand All @@ -212,60 +213,60 @@ target_esptool_test_esp32:
script:
# libffi (needed for espsecure) version keeps changing in python docker images, add a symlink to the installed version
- ln -sfn /usr/lib/arm-linux-gnueabihf/libffi.so.7.1.0 /usr/lib/arm-linux-gnueabihf/libffi.so.6
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP32 esp32 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32 --chip esp32 --baud 115200

# ESP32S2
target_esptool_test_esp32s2:
extends: .target_esptool_test
tags:
- esptool_esp32s2_target
script:
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP32S2 esp32s2 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32S2 --chip esp32s2 --baud 115200

target_esptool_test_esp32s2_usbcdc:
extends: .target_esptool_test
tags:
- esptool_esp32s2_cdc_target
script:
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP32S2_USBCDC esp32s2 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32S2_USBCDC --chip esp32s2 --baud 115200

# ESP32C3
target_esptool_test_esp32c3:
extends: .target_esptool_test
tags:
- esptool_esp32c3_target
script:
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP32C3 esp32c3 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32C3 --chip esp32c3 --baud 115200

# ESP32S3
target_esptool_test_esp32s3:
extends: .target_esptool_test
tags:
- esptool_esp32s3_target
script:
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP32S3 esp32s3 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32S3 --chip esp32s3 --baud 115200

target_esptool_test_esp32s3_usbcdc:
extends: .target_esptool_test
tags:
- esptool_esp32s3_cdc_target
script:
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP32S3_USBCDC esp32s3 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32S3_USBCDC --chip esp32s3 --baud 115200

# ESP32C2
target_esptool_test_esp32c2_40mhz:
extends: .target_esptool_test
tags:
- esptool_esp32c2_40mhz_target
script:
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP32C2_40MHZ esp32c2 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32C2_40MHZ --chip esp32c2 --baud 115200

target_esptool_test_esp32c2_26mhz:
extends: .target_esptool_test
tags:
- esptool_esp32c2_26mhz_target
script:
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_esptool.py /dev/serial_ports/ESP32C2_26MHZ esp32c2 115200
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32C2_26MHZ --chip esp32c2 --baud 115200

combine_reports:
stage: report
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ def find_version(*file_paths):
"flake8-import-order",
"flake8-gl-codeclimate",
"pyelftools",
# the replacement of the old xmlrunner package
"unittest-xml-reporting",
"coverage~=6.0",
"black",
"pre-commit",
"pytest",
"pytest-rerunfailures",
],
},
install_requires=[
Expand Down
20 changes: 20 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def pytest_addoption(parser):
parser.addoption(
"--port", action="store", default="/dev/ttyUSB0", help="Serial port"
)
parser.addoption("--chip", action="store", default="esp32", help="Chip type")
parser.addoption("--baud", action="store", default=115200, help="Baud rate")
parser.addoption(
"--with_trace",
action="store_true",
default=False,
help="Trace interactions",
)


def pytest_configure(config):
global arg_port, arg_chip, arg_baud, arg_trace
arg_port = config.getoption("--port")
arg_chip = config.getoption("--chip")
arg_baud = config.getoption("--baud")
arg_trace = config.getoption("--with_trace")
5 changes: 3 additions & 2 deletions test/test_espsecure.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def run_espsecure(self, args):
output = subprocess.check_output(
[str(s) for s in cmd], cwd=TEST_DIR, stderr=subprocess.STDOUT
)
print(output.decode("utf-8"))
return output.decode("utf-8")
output = output.decode("utf-8")
print(output)
return output
except subprocess.CalledProcessError as e:
print(e.output.decode("utf-8"))
raise e
Expand Down
Loading

0 comments on commit 1d18196

Please sign in to comment.