Skip to main content

pytest plugin for testing Revit API code via RevitDevTool Named Pipe bridge

Project description

RevitDevTool.PyTest

PyPI version Python License: MIT

pytest plugin for testing Revit API code via RevitDevTool Named Pipe bridge. Tests run inside a live Revit process — write standard pytest, execute remotely.

Installation

pip install revitdevtool_pytest

Dependencies

Package Version
Python >= 3.10
pytest >= 9.0
pywin32 >= 311

Requirements

  • Windows (Named Pipes)
  • Revit with RevitDevTool add-in installed and loaded

Project Setup

Recommended: scaffold your project with uv or pixi:

# uv
uv init my-revit-tests
cd my-revit-tests
uv add revitdevtool_pytest

# pixi (uses pyproject.toml as manifest)
pixi init --format pyproject my-revit-tests
cd my-revit-tests
pixi add --pypi revitdevtool_pytest

Configuration

Add plugin settings to [tool.pytest.ini_options] in your pyproject.toml:

[tool.pytest.ini_options]
revit_version = "2025"
revit_launch = false
revit_launch_timeout = "180"
Option Type Default Description
revit_version string Revit version year (e.g. "2025"). Required when revit_launch = true.
revit_launch bool false Force-launch a new Revit instance (skip reusing existing free instances).
revit_timeout string "60" Per-test execution timeout in seconds.
revit_launch_timeout string "120" Seconds to wait for Revit to start.
revit_pipe string Explicit pipe name (bypasses auto-discovery).

CLI flags override INI settings:

pytest --revit-launch --revit-version=2025 -v

Connection Behavior

  • Default (revit_launch = false): plugin auto-discovers a running Revit instance matching revit_version via Named Pipe scan. If none found, exits with error.
  • Force launch (revit_launch = true): always spawns a new Revit process, waits for its pipe to appear, then connects. Existing instances are ignored.

Print Output

Captured print() output from tests running inside Revit is automatically shown in the terminal for passing tests (equivalent to -rP). No extra flags needed.

Usage

Fixtures

Define fixtures in conftest.py that provide Revit API objects:

import pytest

@pytest.fixture(scope="session")
def revit_uiapp():
    return __revit__  # UIApplication injected by RevitDevTool

@pytest.fixture(scope="session")
def revit_app(revit_uiapp):
    return revit_uiapp.Application

@pytest.fixture(scope="session")
def revit_doc(revit_uiapp):
    return revit_uiapp.ActiveUIDocument.Document

Writing Tests

def test_active_view(revit_doc):
    view = revit_doc.ActiveView
    print(f"Active View: {view.Name}")
    assert view.Name is not None

def test_revit_version(revit_app):
    assert "2025" in revit_app.VersionName

PEP 723 Dependencies

Declare test-suite dependencies in conftest.py using PEP 723 metadata. RevitDevTool auto-installs them before test execution:

# /// script
# dependencies = [
#   "numpy>=2.0",
#   "polars>=1.0",
# ]
# ///

Running Tests

# With pyproject.toml configured:
pytest

# Override version for a single run:
pytest --revit-version=2026 -v

# Using uv or pixi:
uv run pytest
pixi run pytest

How It Works

  1. pytest discovers and collects tests locally
  2. Plugin intercepts pytest_runtestloop, connects to Revit via Named Pipe
  3. Test nodeids are sent to Revit's PytestRunner.py (embedded in RevitDevTool)
  4. Tests execute inside Revit's Python.NET environment with full API access
  5. Results (pass/fail/skip, stdout, stderr, tracebacks) are returned via pipe
  6. Plugin maps results back to standard pytest reports

IDE Integration

VS Code / Cursor

{
    "python.testing.pytestEnabled": true,
    "python.testing.pytestArgs": ["tests"]
}

PyCharm

Enable pytest as the test runner. Plugin auto-detects IDE adapters and disables streaming to avoid duplicate results in the test tree.

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

revitdevtool_pytest-0.2.0.tar.gz (56.8 kB view details)

Uploaded Source

Built Distribution

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

revitdevtool_pytest-0.2.0-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: revitdevtool_pytest-0.2.0.tar.gz
  • Upload date:
  • Size: 56.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for revitdevtool_pytest-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9e2751455775b135fb724bdb7dda8dfd4726a71bf248715fe254a0d80aedaa51
MD5 4365e19ac9168b81e1449037851c7892
BLAKE2b-256 748e79b890b18432d3430e4e8c966ad27e27aab0a1a575ccd3b016acf6a74d9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for revitdevtool_pytest-0.2.0.tar.gz:

Publisher: publish.yml on trgiangv/RevitDevTool.PyTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for revitdevtool_pytest-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36bbd5b8fdecdf4238471d51f4a6aa288a65ad13516ab7e3db8f5a3ec892a740
MD5 f521340c04945c80338fdb7e3a406d03
BLAKE2b-256 d22019dce0bac235068902485a880fdb17a519f0ba41f1eff98a1d92bd8534ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for revitdevtool_pytest-0.2.0-py3-none-any.whl:

Publisher: publish.yml on trgiangv/RevitDevTool.PyTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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