Skip to content

Commit 1a44190

Browse files
committed
Added support for "socket://" and "rfc2217://" protocols using "test_port" option // Resolve #4229
1 parent 4ef1333 commit 1a44190

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

HISTORY.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ Please check `Migration guide from 5.x to 6.0 <https://docs.platformio.org/en/la
4444

4545
* **Unit Testing**
4646

47-
- New `Unit Testing <https://docs.platformio.org/en/latest/advanced/unit-testing/index.html>`_ solution and documentation
47+
- Refactored from scratch `Unit Testing <https://docs.platformio.org/en/latest/advanced/unit-testing/index.html>`_ solution and its documentation
4848
- New `Test Hierarchies <https://docs.platformio.org/en/latest/advanced/unit-testing/structure.html>`_ (`issue #4135 <https://github.com/platformio/platformio-core/issues/4135>`_)
4949
- New `Custom Testing Framework <https://docs.platformio.org/en/latest/advanced/unit-testing/frameworks/custom/index.html>`_
5050
- New "test" `build configuration <https://docs.platformio.org/en/latest/projectconf/build_configurations.html>`__
51+
- Added support for ``socket://`` and ``rfc2217://`` protocols using `test_port <https://docs.platformio.org/en/latest/projectconf/section_env_test.html#test-port>`__ option (`issue #4229 <https://github.com/platformio/platformio-core/issues/4229>`_)
5152
- Generate reports in JUnit and JSON formats using the `pio test --output-format <https://docs.platformio.org/en/latest/core/userguide/cmd_test.html#cmdoption-pio-test-output-format>`__ option (`issue #2891 <https://github.com/platformio/platformio-core/issues/2891>`_)
5253
- Provide more information when the native program crashed on a host (errored with a negative return code) (`issue #3429 <https://github.com/platformio/platformio-core/issues/3429>`_)
5354
- Fixed an issue when command line parameters (``--ignore``, ``--filter``) do not override values defined in the |PIOCONF| (`issue #3845 <https://github.com/platformio/platformio-core/issues/3845>`_)

docs

platformio/test/runners/base.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ def get_test_speed(self):
7676
self.project_config.get(f"env:{self.test_suite.env_name}", "test_speed")
7777
)
7878

79+
def get_test_port(self):
80+
return self.options.test_port or self.project_config.get(
81+
f"env:{self.test_suite.env_name}", "test_port"
82+
)
83+
7984
def start(self, cmd_ctx):
8085
# setup command context
8186
self.cmd_ctx = cmd_ctx
@@ -138,9 +143,11 @@ def stage_testing(self):
138143
if self.options.without_testing:
139144
return None
140145
click.secho("Testing...", bold=self.options.verbose)
146+
test_port = self.get_test_port()
147+
serial_conds = [self.platform.is_embedded(), test_port and "://" in test_port]
141148
reader = (
142149
SerialTestOutputReader(self)
143-
if self.platform.is_embedded()
150+
if any(serial_conds)
144151
else ProgramTestOutputReader(self)
145152
)
146153
return reader.begin()

platformio/test/runners/readers/serial.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ def begin(self):
3636
click.echo()
3737

3838
try:
39-
ser = serial.Serial(
40-
baudrate=self.test_runner.get_test_speed(), timeout=self.SERIAL_TIMEOUT
39+
ser = serial.serial_for_url(
40+
self.test_runner.get_test_port() or self.autodetect_test_port(),
41+
do_not_open=True,
42+
baudrate=self.test_runner.get_test_speed(),
43+
timeout=self.SERIAL_TIMEOUT,
4144
)
42-
ser.port = self.get_test_port()
4345
ser.rts = self.test_runner.options.monitor_rts
4446
ser.dtr = self.test_runner.options.monitor_dtr
4547
ser.open()
@@ -74,17 +76,7 @@ def begin(self):
7476
self.test_runner.on_test_output(line)
7577
ser.close()
7678

77-
def get_test_port(self):
78-
# if test port is specified manually or in config
79-
port = (
80-
self.test_runner.options.test_port
81-
or self.test_runner.project_config.get(
82-
f"env:{self.test_runner.test_suite.env_name}", "test_port"
83-
)
84-
)
85-
if port:
86-
return port
87-
79+
def autodetect_test_port(self):
8880
board = self.test_runner.project_config.get(
8981
f"env:{self.test_runner.test_suite.env_name}", "board"
9082
)

0 commit comments

Comments
 (0)