Skip to main content

A pytest plugin that enables tmux driven tests

Project description

pytest-tmux

PyPI version

Python versions

A pytest plugin that enables tmux driven tests

This plugin is intend to help users who whant to test interrative cli.

When using tmux fixture it basically :

  • creates a tmux server (socket created in tmux tmpdir)
  • creates a session automatically
  • attach to the window automatically
  • attach to the pane automatically

Warnings

Until a stable release, it is greatly encouraged to specify a strict version if you use this tool in your CI since it is in its early development and could be greatly changed between version.

Docs

https://pytest-tmux.readthedocs.io/

Features

  • Enable tmux driven tests
  • Enable screen assertion with retry
  • Enable row assertion with retry
  • Allow to debug tests interactively

Requirements

  • python >= 3.7
  • pytest
  • tmux

Installation

You can install "pytest-tmux" via pip from PyPI:

$ pip install pytest-tmux

Configuration capabilities

Configuration could be set on different level (in order of precedence):

  • Server
    • by overriding tmux_server_config (scope='session') fixture
    • env var
    • cli args (see --tmux-* switch with pytest --help)
  • Session
    • by overriding tmux_session_config fixture
    • at the test level with tmux_session_cfg marker
    • dynamically inside test with tmux.config.session
    • env var
    • cli args (see --tmux-* switch with pytest --help)
  • Assertion
    • by overriding tmux_assertion_config fixture
    • at the test level with tmux_assertion_cfg marker
    • dynamically inside test with tmux.config.session
    • when calling tmux.screen() / tmux.row() with timeout / delay argument
    • env var
    • cli args (see --tmux-* switch with pytest --help)

Usage

Basic example

import pytest
from inspect import cleandoc

def test_assert(tmux):
    # Set some options before session / windows is started
    tmux.config.session.window_command='env -i PS1="$ " TERM="xterm-256color" /usr/bin/env bash --norc --noprofile'
    assert tmux.screen() == '$'
    tmux.send_keys(r'printf "  Hello World  .\n\n"')
    expected=r"""
    $ printf "  Hello World  .\n\n"
      Hello World  .

    $
    """
    assert tmux.screen() == cleandoc(expected)

License

Distributed under the terms of the MIT license, "pytest-tmux" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_tmux-0.0.3.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

pytest_tmux-0.0.3-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest_tmux-0.0.3.tar.gz.

File metadata

  • Download URL: pytest_tmux-0.0.3.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.7.16 Linux/4.15.0-197-generic

File hashes

Hashes for pytest_tmux-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ee942a68bf009162523590edc72d965390b0d02566bae6d970c4452a4b489074
MD5 497415a7684a543a91c8285f71eb853a
BLAKE2b-256 f4e3c23e8257f2f1d92f048e3b1cd31a0088a99372be35802ff31e1a9181ab2a

See more details on using hashes here.

File details

Details for the file pytest_tmux-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pytest_tmux-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.7.16 Linux/4.15.0-197-generic

File hashes

Hashes for pytest_tmux-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 51f6c096c35b3c4f8f0bd9aa8f2bf0ab9fe558e790c393cf424f06e535891a63
MD5 af5a8056a508350ae6f1f0e2e06e2c58
BLAKE2b-256 4d83e58e79a50d832acd0c94d9926a74bff85f09369a1bbe567273e9c668b7d7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page