Skip to content

Commit e5d06e0

Browse files
committed
docs: small fixes
1 parent a7f4999 commit e5d06e0

File tree

6 files changed

+200
-211
lines changed

6 files changed

+200
-211
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pytest-embedded
22

3-
[![Documentation Status](https://readthedocs.com/projects/espressif-pytest-embedded/badge/?version=latest)](https://docs.espressif.com/projects/pytest-embedded/en/latest/?badge=latest) ![Python 3.7+](https://img.shields.io/pypi/pyversions/pytest-embedded)
3+
[![Documentation Status](https://readthedocs.com/projects/espressif-pytest-embedded/badge/?version=latest)](https://docs.espressif.com/projects/pytest-embedded/en/latest/?badge=latest) ![Python 3.10+](https://img.shields.io/pypi/pyversions/pytest-embedded)
44

55
A pytest plugin that has multiple services available for various functionalities. Designed for embedded testing.
66

@@ -17,15 +17,15 @@ A pytest plugin that has multiple services available for various functionalities
1717

1818
Packages under this repo mainly use semantic versioning. Sometimes a bug fix version may contain some non-breaking new features as well.
1919

20-
It is recommended to use `~=1.0` to get rid of breaking changes, and use the latest new features. For example,
20+
It is recommended to use `~=2.0` to get rid of breaking changes, and use the latest new features. For example,
2121

2222
```shell
23-
pip install -U pytest-embedded~=1.0
23+
pip install -U pytest-embedded~=2.0
2424
```
2525

2626
## Quickstart
2727

28-
- `pip install -U pytest-embedded~=1.0`
28+
- `pip install -U pytest-embedded~=2.0`
2929
- Create a file `test_basic.py`
3030

3131
```python

docs/concepts/key-concepts.md

Lines changed: 0 additions & 149 deletions
This file was deleted.

docs/concepts/key-concepts.rst

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
##############
2+
Key Concepts
3+
##############
4+
5+
**********
6+
Fixtures
7+
**********
8+
9+
Each test case initializes a few fixtures. The most important fixtures are:
10+
11+
- ``msg_queue``: A message queue. A background listener process reads all messages from this queue, logs them to the terminal with an optional timestamp, and records them to the pexpect process.
12+
- ``pexpect_proc``: A pexpect process that can run ``pexpect.expect()`` for testing purposes.
13+
- ``app``: The built binary.
14+
- ``dut``: Device Under Test (DUT). A DUT contains several daemon processes/threads, and the output of each is redirected to the ``msg_queue`` fixture.
15+
16+
.. note::
17+
18+
You may redirect any output to the ``msg_queue`` fixture by ``contextlib.redirect_stdout``.
19+
20+
.. code:: python
21+
22+
import contextlib
23+
24+
def test_redirect(dut, msg_queue):
25+
with contextlib.redirect_stdout(msg_queue):
26+
print("will be redirected")
27+
28+
dut.expect_exact("redirected")
29+
30+
Or you may redirect the output from a fixture ``redirect``
31+
32+
.. code:: python
33+
34+
def test_redirect(dut, msg_queue, redirect):
35+
with redirect():
36+
print("will also be redirected")
37+
38+
dut.expect_exact("redirected")
39+
40+
You can run ``pytest --fixtures`` to see all fixtures defined by ``pytest-embedded``. They are listed under the ``fixtures defined from pytest_embedded.plugin`` section.
41+
42+
*****************
43+
Parametrization
44+
*****************
45+
46+
All CLI options support parametrization via ``indirect=True``. Parametrization is a feature provided by ``pytest``. For more details, please refer to the `Parametrizing tests <https://docs.pytest.org/en/stable/example/parametrize.html>`_ documentation.
47+
48+
For example, running the ``pytest`` command with the following test script:
49+
50+
.. code:: python
51+
52+
@pytest.mark.parametrize(
53+
"embedded_services, app_path",
54+
[
55+
("idf", app_path_1),
56+
("idf", app_path_2),
57+
],
58+
indirect=True,
59+
)
60+
def test_serial_tcp(dut):
61+
assert dut.app.target == "esp32"
62+
dut.expect("Restart now")
63+
64+
is equivalent to running two separate commands, ``pytest --embedded-services idf --app-path <app_path_1>`` and ``pytest --embedded-services idf --app-path <app_path_2>``, with this test script:
65+
66+
.. code:: python
67+
68+
def test_serial_tcp(dut):
69+
assert dut.app.target == "esp32"
70+
dut.expect("Restart now")
71+
72+
**********
73+
Services
74+
**********
75+
76+
You can activate additional services with ``pytest --embedded-services service[,service]`` to enable extra fixtures and functionalities. These services are provided by optional dependencies, which can be installed with ``pip``.
77+
78+
Available services are described :doc:`here <services>`.
79+
80+
************
81+
Multi DUTs
82+
************
83+
84+
Sometimes, you may need multiple DUTs for testing, for example, in master-slave or mesh network tests.
85+
86+
Here are a few examples of how to enable this feature. For detailed information, refer to the ``embedded`` group in the ``pytest --help`` output.
87+
88+
Enable multi DUTs by specifying ``--count``
89+
===========================================
90+
91+
When multi-DUT mode is enabled, all fixtures become a tuple of instances. Each instance in the tuple is independent. For parametrization, each configuration uses ``|`` as a separator for each instance's values.
92+
93+
For example, running shell command:
94+
95+
.. code:: shell
96+
97+
pytest \
98+
--embedded-services serial|serial \
99+
--count 2 \
100+
--app-path <master_bin>|<slave_bin>
101+
102+
enables two DUTs with the ``serial`` service. The ``app`` fixture becomes a tuple of two ``App`` instances, and ``dut`` becomes a tuple of two ``Dut`` instances.
103+
104+
You can test with:
105+
106+
.. code:: python
107+
108+
def test(dut):
109+
master = dut[0]
110+
slave = dut[1]
111+
112+
master.expect("sent")
113+
slave.expect("received")
114+
115+
Specify once when applying to all DUTs
116+
======================================
117+
118+
If all DUTs share the same configuration value, you only need to specify it once.
119+
120+
.. code:: shell
121+
122+
pytest \
123+
--embedded-services serial \
124+
--count 2 \
125+
--app-path <master_bin>|<slave_bin>
126+
127+
The ``--embedded-services serial`` option applies to all DUTs.
128+
129+
Vacant Value if it's Useless
130+
============================
131+
132+
Sometimes, an option is only useful for a specific service. You can provide a vacant value if a configuration is not applicable to a particular DUT.
133+
134+
.. code:: shell
135+
136+
pytest \
137+
--embedded-services qemu|serial \
138+
--count 2 \
139+
--app-path <master_bin>|<slave_bin> \
140+
--qemu-cli-args "<args>|" \
141+
--port "|<port>"
142+
143+
The ``--qemu-cli-args`` option applies to the first DUT (with the ``qemu`` service), while ``--port`` applies to the second DUT (with the ``serial`` service).
144+
145+
*********
146+
Logging
147+
*********
148+
149+
``pytest-embedded`` prints all DUT output with a timestamp. To remove the timestamp, run pytest with the ``--with-timestamp n`` option.
150+
151+
By default, ``pytest`` swallows ``stdout``. To see the live output, run pytest with the ``-s`` option.

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
project_homepage = 'https://github.com/espressif/pytest-embedded'
1313
copyright = f'2023-{datetime.now().year}, Espressif Systems (Shanghai) Co., Ltd.' # noqa: A001
1414
author = 'Fu Hanxi'
15-
version = '1.x'
16-
release = '1.x'
15+
version = '2.x'
16+
release = '2.x'
1717

1818
# -- General configuration ---------------------------------------------------
1919
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

0 commit comments

Comments
 (0)