What is this?
pytest_tuitest is a pytest plugin for testing TUI (text/terminal user interface) and regular command-line applications.
It allows you to run an application in a virtual terminal and run assertions on the contents and colors of its output. It uses pyte for terminal emulation.
What can it do?
Here are some examples to give you a taste of what can be done.
import pytest_tuitest as tt
# You can simply run an application and verify that it prints
# the expected output in the terminal.
@tt.test_executable("grep")
@tt.with_arguments(["--color=always", "pytest_tuitest"])
@tt.with_stdin("This is a pytest_tuitest demo")
def test_grep_marks_the_output_according_to_arguments(terminal):
terminal.wait_for_finished()
# You can get the text in the terminal
assert terminal.get_string_at(line=0, column=10, length=14) == "pytest_tuitest"
# The color
assert terminal.get_foreground_at(line=0, column=10) == tt.Color16.RED
assert terminal.get_background_at(line=0, column=10) == tt.Color16.DEFAULT
# Or the font style
assert not terminal.has_style_at(line=0, column=10, style=tt.Style.BLINKING)
# You can also send stdin and capture stdout. Capturing stdout
# is useful in cases where TUI is printed on TTY and something
# else is printed on stdout (e.g. in case of fzf). That way, you
# can independently check what's in the TUI and what's "returned".
@tt.test_executable("fzf")
@tt.with_terminal_size(columns=80, lines=40)
@tt.with_stdin("things\nstuff")
@tt.with_captured_stdout(True)
def test_sending_input_and_capturing_output(terminal):
terminal.wait_for_stable_output()
assert terminal.get_string_at(line=39, column=0, length=1) == ">"
# Emulate typing of "th" and pressing enter
terminal.send("th\r\n")
(status, stdout, _) = terminal.wait_for_finished()
assert status == 0
assert stdout == "things\n"
Installation
pip install pytest-tuitest
This will automatically install pytest as well.
Metadata
Release files for pytest-tuitest 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_tuitest-0.1.0.tar.gz | 26.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_tuitest-0.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 41.1 kB
Release files / pytest_tuitest-0.1.0.tar.gz
| Download URL | pytest_tuitest-0.1.0.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
08117075273daaa510436679d63c720d60bc5481abe37340a83010051c75dcdf
|
|
BLAKE2b-256 checksum How to use checksums |
e0169be83112a0b622a93811a05bfa71ab1d74f3ad87e7232765b7a10cbd2ac6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / pytest_tuitest-0.1.0-py2.py3-none-any.whl
| Download URL | pytest_tuitest-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a52e3530e1083c949deab2305098e07239fafdc20a9cd2526e49815975f5b85e
|
|
BLAKE2b-256 checksum How to use checksums |
3df963f99a174eec0820007ced0786d43533636434c44edc876a294ce64971ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|