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-0.0.1.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-0.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: klab_pytest_toolkit_prompt-0.0.1.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-0.0.1.tar.gz
Algorithm Hash digest
SHA256 378971f3fc8d0445b515adc6a2b779add8a4db007c8618e2880ef88a4680db17
MD5 c7a6819d7875de0941e2a4cbf90482ad
BLAKE2b-256 6cae3196ac5b2e75eeca3321fd20bc197614313da432390693c662c6f60b05f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klab_pytest_toolkit_prompt-0.0.1-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-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3217291468b485ae298579904c18eb031d4da8ae71de84ff9b17f5952f41470c
MD5 548c700a6eee567377dda0ecaef8218b
BLAKE2b-256 f8ef2b145a1a7d7aa5dfe9f3dd29c1a437ffe70217ae34050c891380161fea7b

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