1import pytest
2
3
4def pytest_addoption(parser):
5    # test_esptool.py and test_espefuse.py
6    parser.addoption(
7        "--port", action="store", default="/dev/ttyUSB0", help="Serial port"
8    )
9    parser.addoption("--chip", action="store", default="esp32", help="Chip type")
10
11    # test_esptool.py only
12    parser.addoption("--baud", action="store", default=115200, help="Baud rate")
13    parser.addoption("--with-trace", action="store_true", default=False, help="Trace")
14    parser.addoption(
15        "--preload-port",
16        action="store",
17        default=False,
18        help="Port for dummy binary preloading for USB-JTAG/Serial tests",
19    )
20
21    # test_espefuse.py only
22    parser.addoption(
23        "--reset-port", action="store", default=None, help="FPGA reset port"
24    )
25
26
27def pytest_configure(config):
28    # test_esptool.py and test_espefuse.py
29    global arg_port, arg_chip
30    arg_port = config.getoption("--port")
31    arg_chip = config.getoption("--chip")
32
33    # test_esptool.py only
34    global arg_baud, arg_trace, arg_preload_port
35    arg_baud = config.getoption("--baud")
36    arg_trace = config.getoption("--with-trace")
37    arg_preload_port = config.getoption("--preload-port")
38
39    # test_espefuse.py only
40    global arg_reset_port
41    arg_reset_port = config.getoption("--reset-port")
42
43    # register custom markers
44    config.addinivalue_line(
45        "markers",
46        "host_test: mark esptool tests that run on the host machine only "
47        "(don't require a real chip connected).",
48    )
49
50    config.addinivalue_line(
51        "markers",
52        "quick_test: mark esptool tests checking basic functionality.",
53    )
54
55
56def need_to_install_package_err():
57    pytest.exit(
58        "To run the tests, install esptool in development mode. "
59        "Instructions: https://docs.espressif.com/projects/esptool/en/latest/"
60        "contributing.html#development-setup"
61    )
62