Skip to main content

pytest-dpg is a pytest plugin for testing Dear PyGui (DPG) applications

Project description


PyPI version Python Versions Stars


About

pytest-dpg is a pytest plugin for testing DearPyGui (DPG) applications.

Features

  • Automates user interactions like clicking buttons, switching tabs, and dragging sliders
  • Runs GUI tests in a separate process for concurrency, stability, and isolation
  • Easy to use API for interacting with DPG elements
  • Requires no application code modifications

Installation

pipx is recommended although any package manager that supports pyproject.toml files can be used.

pipx install pytest-dpg

How it works

pytest-dpg creates a controlled environment for testing before performing introspection on the application:

  • DPG Loop Patching: dpgtester patches DearPyGui's main loop (dpg.start_dearpygui()) with a custom loop that allows for command insertion between frames.
  • Item Identification: utilizes DPG's internal APIs to locate items based on their labels, values, or adjacent items. This allows it to (hopefully) find the correct screen coordinates for interactions.

Usage

pytest-dpg automatically makes the pytest fixture dpgtester available for use

def test_my_gui(dpgtester):
    # This function should setup and start your application when run
    func = your_gui_function

    # Start your GUI application
    dpgtester.set_target(func)
    dpgtester.start_gui()

    # Interact with GUI elements
    dpgtester.click_button("Submit")
    dpgtester.click_tab("Settings")
    dpgtester.drag_slider("Volume", 75)

Limitations

While pytest-dpg aims to provide a robust testing solution for DearPyGui applications, there are some current limitations to be aware of:

  • Limited Application Support: only applications that utilize dpg.start_dearpygui() are curently supported

  • Limited Widget Support: only the following widgets are currently supported

    • regular button
    • horizontal slider
    • tab
    • collapsible header
  • Complex Layouts: Very complex or dynamically changing layouts might pose challenges for element identification and interaction.

We are continuously working on improving pytest-dpg and addressing these limitations. Contributions and feedback are always welcome!

API Reference

dpgtester

  • set_target(func: Callable) Set the target function for the GUI test
  • start_gui() Start the GUI in a separate process
  • python stop_gui() Stop the GUI process if it's running
  • click_button(label: str) Click a button with the given label
  • click_tab(label: str) Click a tab with the given label
  • drag_slider(label: str, value: int) Drag a slider to the specified value

pytest_dpg

By default, dpgtester will execute actions as quickly as possible. To slow down interactions, the following attributes can be increased

import pytest_dpg

pytest_dpg.PAUSE = 0.25
pytest_dpg.MINIMUM_DURATION = 0.5

Support

Reach out to the maintainer at one of the following places:

If you want to say thank you or/and support active development of pytest-dpg consider adding a GitHub Star to the project.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  • Fork the repository
  • Create your feature branch (git checkout -b feature/AmazingFeature)
  • Commit your changes (git commit -m 'Add some AmazingFeature')
  • Push to the branch (git push origin feature/AmazingFeature)
  • Open a Pull Request

For a full list of all authors and contributors, see the contributors page.

License

This project is licensed under the GNU General Public License v3.

See LICENSE for more information.

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_dpg-0.1.3.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

pytest_dpg-0.1.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_dpg-0.1.3.tar.gz.

File metadata

  • Download URL: pytest_dpg-0.1.3.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pytest_dpg-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7ab915f148c13c5742214cbb361d691fd2f158e1034be429da03ce134531f852
MD5 b57e5ce989c009b2f3d4fc6899b607d8
BLAKE2b-256 9e345b72c5ad8ded4cea9b5e93ec47afcc531f59a3234453b84f3e7c43ad4f63

See more details on using hashes here.

File details

Details for the file pytest_dpg-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pytest_dpg-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pytest_dpg-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d601933e6c5d367941ee5275ed5bf0c71795a13d320d295d7315127ab6752e4
MD5 ac0e99aa5e03b4f53afae30f01219c61
BLAKE2b-256 f15579fa942bc77239f2d396d63e836586f061ff89595334826aafc164b9611e

See more details on using hashes here.

Supported by

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