Skip to main content

Pytest prompt fixtures for the Klab Pytest Toolkit

Project description

Klab Pytest Toolkit - Prompt

Custom pytest fixtures for interactive user prompts during test execution using tkinter UI dialogs. The goal is to allow testers to interact with the test process, providing confirmations or displaying important information.

At the moment the package provides the following fixtures:

  • ui_prompt_factory: Factory for creating multiple prompt instance. With the factory you can create the prompt fixture.

Installation

pip install klab-pytest-toolkit-prompt

Usage

UI Prompt

Create the fixture

The factory class PromptFactory can be used to create multiple prompt instances. This is already provided as a pytest fixture prompt_factory.

@pytest.fixture
def ui_prompt(prompt_factory) -> PromptInterface:
    """Fixture to provide a UI prompt interface for user interaction during tests."""
    return prompt_factory.create_prompt(prompt_type=PromptFactory.PromptType.UI_PROMPT)

Functions

The following functions are available on the PromptInterface instance:

Show Information Dialog

def test_with_info(ui_prompt):
    """Display information to the user."""
    ui_prompt.show_info("Test is about to perform a critical operation")
    
    # Continue with test
    perform_operation()

Get User Confirmation

def test_with_confirmation(ui_prompt):
    """Get user confirmation before proceeding."""
    if ui_prompt.confirm_action("Continue with destructive test?"):
        # User clicked Yes
        perform_destructive_operation()
    else:
        # User clicked No
        pytest.skip("User cancelled the test")

With Timeout (Auto-close)

def test_with_timeout(ui_prompt):
    """Show dialog that auto-closes after timeout."""
    # Dialog closes automatically after 5 seconds
    ui_prompt.show_info("This will auto-close in 5 seconds", timeout=5)
    
    # Confirmation dialog with timeout (returns False if timeout expires)
    result = ui_prompt.confirm_action(
        "Click within 10 seconds",
        timeout=10
    )

Examples

See the tests directory for example test cases demonstrating the usage of the prompt fixtures.

License

MIT

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

klab_pytest_toolkit_prompt-1.0.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

klab_pytest_toolkit_prompt-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: klab_pytest_toolkit_prompt-1.0.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for klab_pytest_toolkit_prompt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b6c8e483f584043402e3e7f9c7655caa69cf4bfbfcdebdb1a2b4433b20dc8285
MD5 5bcee5f83f748c033f47796cc0e42d50
BLAKE2b-256 3c952dcde434d30abdb55cc1a7b0e54a3f2b7e82cd0686cad70d1ee5738ab957

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klab_pytest_toolkit_prompt-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for klab_pytest_toolkit_prompt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dca471f5aa5cd9c9ee53034c120dec546a30bfa0ecefb51619f11c392e9235aa
MD5 08b8e46d72b73b3a175c54b9a6f001da
BLAKE2b-256 8c8ff33f9850068e78243e7020f15b4229367ce5f995a5fb6712b7d272a7ccea

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