Skip to main content

A Pytest plugin and command line tool for interactive testing with Pytest

Project description

pytest-gak

GAK is a plugin and CLI for using pytest to run interactive test suites, using prompts.

Motivation

Pytest is typically intended for running fully automated tests. However, some tests aren't possible to fully automate. A particular use case is testing drivers for live hardware - for instance, executing a driver API and manually inspecting the hardware to confirm its state. This library helps solve that use case.

Install

GAK is available on PyPI, and can be installed like so:

pip install pytest-gak

This will automatically register as a plugin to Pytest, and expose a script called gaktest.

Usage

Plugin

The plugin exposes some new fixtures:

  • confirm: Confirm that a state is as expected
  • take_action: Prompt the developer to take a physical action before continuing
  • check: Check that a state is as expected

For example, the plusdeck project has a test which looks like this:

async def test_manual_no_events(check, confirm, take_action) -> None:
    """
    Plus Deck plays tapes manually without state subscription.
    """

    confirm("There is NO tape in the deck")

    client = await create_connection(CONFIG.port)

    @client.events.on("state")
    def unexpected_state(state: State):
        assert not state, "Should not receive state before enabling"

    take_action("Put a tape in the deck")

    check("Press Rewind. Has the tape rewound?", "Deck rewound")
    check("Press Play Side A. Is the deck playing side A?", "Deck is playing side A")
    check("Press Pause. Is the tape paused?", "Deck is paused")
    check("Press Pause. Is the tape playing?", "Deck is playing")
    check("Press Fast-Forward. Has the tape fast-forwarded?", "Deck fast-forwarded")
    check("Press Play Side B. Is the deck playing side B?", "Deck is playing side B")
    check("Press Stop. Has the tape has stopped playing?", "Deck is stopped")
    check("Press Eject. Did the tape eject?", "Deck has ejected")

    client.events.remove_listener("state", unexpected_state)

    client.close()

Command Line

Pytest allows you to disable capturing of output using the capsys fixture. However, this fixture does not allow for disabling the capture of stdin. Therefore, in order to run tests requiring prompts, you need to run pytest with the --capture=no setting (or with the -s short flag).

GAK comes with a wrapper script that will add this flag to Pytest's arguments. So instead of running:

pytest -s ./tests/test_interactive.py

you may run:

gaktest ./tests/test_interactive.py

A Note on Naming

GAK is named after the Geek At Keyboard testing concept, as popularized by Geepaw Hill. Though, it's worth noting that the actual use of this library is distinct from Geepaw Hill's GAK concept.

GAK testing is what Geepaw calls interactive, ad-hoc testing of a program - "running the program to see how it works right now". This is the sort of testing that most developers do on-the-fly, without thinking about it. pytest-gak, on the other hand, partially automates these sort of tests into an automated "runbook", making them less ad-hoc - but still interactive.

Even so, the use cases are similar. For instance, Geepaw will often GAK test UIs, which are notoriously difficult to automate. In theory, pytest-gak would work here as well.

Changelog

See CHANGELOG.md.

License

Apache-2.0, see LICENSE.

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_gak-2.0.0.tar.gz (31.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_gak-2.0.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_gak-2.0.0.tar.gz.

File metadata

  • Download URL: pytest_gak-2.0.0.tar.gz
  • Upload date:
  • Size: 31.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.12

File hashes

Hashes for pytest_gak-2.0.0.tar.gz
Algorithm Hash digest
SHA256 1e6aef3f1aa007ed50a5fb974d8745ffd99d5f6c0408414e2237d264080690a4
MD5 d2e0dd66591e1c963f221931e441c2a2
BLAKE2b-256 b3618c5b44e0aeae196160fc4e337367eb05fa16fef5cc6259ed595127aac527

See more details on using hashes here.

File details

Details for the file pytest_gak-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_gak-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a59a19d2a5bd1b4d24438358a30c9f08b14a6fe07543980ae87d5fb10cbe0a96
MD5 67452a57c95e570fe8dd9ceb35343d63
BLAKE2b-256 95f8fe70112fded135a43360f896192b850d12f4eb76e23c5152a6f579d2bc0e

See more details on using hashes here.

Supported by

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