1.. zephyr:code-sample:: pytest_shell
2   :name: Pytest shell application testing
3
4   Execute pytest tests against the Zephyr shell.
5
6Overview
7********
8
9The sample project illustrates usage of pytest framework integrated with
10Twister test runner.
11
12A simple application provides basic Zephyr shell interface. Twister builds it
13and then calls pytest in subprocess which runs tests from
14``pytest/test_shell.py`` file. The first test verifies valid response for
15``help`` command, second one verifies if application is able to return
16information about used kernel version. Both tests use ``shell`` fixture, which
17is defined in ``pytest-twister-harness`` plugin. More information about plugin
18can be found :ref:`here <integration_with_pytest>`.
19
20Requirements
21************
22
23Board (hardware, ``native_sim`` or ``QEMU``) with UART console.
24
25Building and Running
26********************
27
28Build and run sample by Twister:
29
30.. code-block:: console
31
32   $ ./scripts/twister -vv --platform native_sim -T samples/subsys/testsuite/pytest/shell
33
34
35Sample Output
36=============
37
38.. code-block:: console
39
40    ...
41    samples/subsys/testsuite/pytest/shell/pytest/test_shell.py::test_shell_print_help
42    INFO: send "help" command
43    DEBUG: #: uart:~$ help
44    DEBUG: #: Please press the <Tab> button to see all available commands.
45    DEBUG: #: You can also use the <Tab> button to prompt or auto-complete all commands or its subcommands.
46    DEBUG: #: You can try to call commands with <-h> or <--help> parameter for more information.
47    DEBUG: #: Shell supports following meta-keys:
48    DEBUG: #: Ctrl + (a key from: abcdefklnpuw)
49    DEBUG: #: Alt  + (a key from: bf)
50    DEBUG: #: Please refer to shell documentation for more details.
51    DEBUG: #: Available commands:
52    DEBUG: #: clear    :Clear screen.
53    DEBUG: #: device   :Device commands
54    DEBUG: #: devmem   :Read/write physical memory
55    DEBUG: #:             Usage:
56    DEBUG: #:             Read memory at address with optional width:
57    DEBUG: #:             devmem address [width]
58    DEBUG: #:             Write memory at address with mandatory width and value:
59    DEBUG: #:             devmem address <width> <value>
60    DEBUG: #: help     :Prints the help message.
61    DEBUG: #: history  :Command history.
62    DEBUG: #: kernel   :Kernel commands
63    DEBUG: #: rem      :Ignore lines beginning with 'rem '
64    DEBUG: #: resize   :Console gets terminal screen size or assumes default in case the
65    DEBUG: #:             readout fails. It must be executed after each terminal width change
66    DEBUG: #:             to ensure correct text display.
67    DEBUG: #: retval   :Print return value of most recent command
68    DEBUG: #: shell    :Useful, not Unix-like shell commands.
69    DEBUG: #: uart:~$
70    INFO: response is valid
71    PASSED
72    samples/subsys/testsuite/pytest/shell/pytest/test_shell.py::test_shell_print_version
73    INFO: send "kernel version" command
74    DEBUG: #: uart:~$ kernel version
75    DEBUG: #: Zephyr version 3.5.99
76    DEBUG: #: uart:~$
77    INFO: response is valid
78    PASSED
79    ...
80