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-1.0.0.tar.gz (43.5 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-1.0.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest_gak-1.0.0.tar.gz
Algorithm Hash digest
SHA256 09f723bcf03ea0fe3c58aa4847ce18aa2b8ff7b678512d17756fc3ae5583c6ca
MD5 b2fee89692a9403241b166805c7c36ff
BLAKE2b-256 afc399ccd212a60f57a7da415ede9271c3d23dcd1d65c15d73f70c7a80c1e72d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_gak-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for pytest_gak-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3e5528b06e0b0f40a1a64a1a3994680bb15de988638cca4d1f6325cd579e9ad
MD5 a2d3d75b759527c4939584529cc5d74d
BLAKE2b-256 81c97e68e2525bbf288f0064647146ad98d20cec5cf653d51ef01463773a6062

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