The pytest-pexpect
plugin aims to streamline CLI testing, a common practice in network and system-related software development and administration tasks. CLI testing encompasses various types of tests, including unit, integration, system, and acceptance tests.
Pytest is a well-known Python test framework with rich features and flexibility.
Pexpect is a Python Expect-like library specifically designed to simulate user CLI interactions, facilitating automated testing of command-line interfaces.
Combining Pytest with Pexpect brings significant advantages to testing CLI applications. With the pytest-pexpect
plugin, you can harness the power of Pytest’s assertions, fixtures, and parametrization alongside Pexpect’s CLI interaction capabilities for seamless and efficient testing of CLI applications. In addition to pexpect
, the plugin adds support for forbidden patterns.
Distributed under the terms of the MIT
license, pytest-pexpect
is free and open source software, see LICNESE file.
For history and releases see CHANGES.adoc file.
You can install pytest-pexpect
plugin with pip3
.
pip3 install pytest-pexpect
git clone https://github.com/novakmi/pytest-pexpect.git pip3 install pytest-pexpect/
ℹ️
|
Or pip3 install . from pytest-pexpect directory.
|
pip3 uninstall pytest-pexpect
Set PYTHONPATH to pytest-pexpect/src
directory
(e.g. export PYTHONPATH=./src:$PYTHONPATH
).
Add into your conftest.py
line
pytest_plugins: str = ("pytest_pexpect")
or add into pytest.ini
lines
[pytest]
addopts = -p pytest_pexpect
--pexpect-dry-run
- if added to command line, pexpect
commands (sendline
, expect
) are not performed
pexpect_shell
fixturefrom pytest_pexpect import ShellParams
@pytest.mark.parametrize("shell", [ShellParams()])
def test_pexpect_object(pexpect_shell):
pexpect_shell.sendline('echo "Hello pexpect"')
pexpect_shell.expect('Hello pexpect', timeout=2)
pexpect_shell.expect_prompt()
The log
directory is created with output log files.
Run full tox
tests
tox
Run full tox
flake8
tests
tox -e flake8
Run pytest
tests
pytest -o log_cli=true -o log_cli_level=DEBUG tests/
-
improve code documentation
-
examples
-
pipy.org package
-
support for test documentation (record
sendline
andexpect
commands)
pytest https://pytest.org
pexpect https://github.com/pexpect/pexpect
Lux (LUcid eXpect scripting) https://github.com/hawk/lux