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

Uploaded Python 3

File details

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

File metadata

  • Download URL: klab_pytest_toolkit_prompt-0.2.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-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7bf18af26d4ca9982b318e00175085423175a73efc0ffe0549be5132f93727a9
MD5 473d1805ede87c02e620a095c49ba8ca
BLAKE2b-256 532973b35b76b35f42059dac633d66e1ffcfcc775c4069cfe68dae0f13fc09b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klab_pytest_toolkit_prompt-0.2.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-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d4758f0cb4a429673abe387d228355da24fb214f19d5e87ddce8d8cb921f253
MD5 29d44c9c68b4a494c3725c2380320d49
BLAKE2b-256 0fdaf29187929113a388ba8a6427d2c171afefbf22497d3b7ef910d5dff3a043

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