revitdevtool-pytest 0.0.3__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/.gitignore +2 -0
  2. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/.vscode/settings.json +0 -6
  3. revitdevtool_pytest-0.2.0/AGENTS.md +112 -0
  4. revitdevtool_pytest-0.2.0/CHANGELOG.md +115 -0
  5. revitdevtool_pytest-0.2.0/CLAUDE.md +1 -0
  6. revitdevtool_pytest-0.2.0/PKG-INFO +193 -0
  7. revitdevtool_pytest-0.2.0/README.md +166 -0
  8. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/pyproject.toml +8 -1
  9. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/src/revitdevtool_pytest/__init__.py +1 -1
  10. revitdevtool_pytest-0.2.0/src/revitdevtool_pytest/bridge.py +212 -0
  11. revitdevtool_pytest-0.2.0/src/revitdevtool_pytest/connection.py +305 -0
  12. revitdevtool_pytest-0.2.0/src/revitdevtool_pytest/constants.py +42 -0
  13. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/src/revitdevtool_pytest/dialog_resolver.py +8 -9
  14. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/src/revitdevtool_pytest/discovery.py +25 -29
  15. revitdevtool_pytest-0.2.0/src/revitdevtool_pytest/models.py +137 -0
  16. revitdevtool_pytest-0.2.0/src/revitdevtool_pytest/plugin.py +258 -0
  17. revitdevtool_pytest-0.2.0/src/revitdevtool_pytest/reporting.py +317 -0
  18. revitdevtool_pytest-0.2.0/src/revitdevtool_pytest/suite_leasing.py +151 -0
  19. revitdevtool_pytest-0.2.0/src/revitdevtool_pytest/suite_lock.py +90 -0
  20. revitdevtool_pytest-0.2.0/tests/_session_probe.py +4 -0
  21. revitdevtool_pytest-0.2.0/tests/conftest.py +103 -0
  22. revitdevtool_pytest-0.2.0/tests/schedule/__init__.py +1 -0
  23. revitdevtool_pytest-0.2.0/tests/schedule/constants.py +63 -0
  24. revitdevtool_pytest-0.2.0/tests/schedule/contracts.py +427 -0
  25. revitdevtool_pytest-0.2.0/tests/schedule/custom_workflow.py +327 -0
  26. revitdevtool_pytest-0.2.0/tests/schedule/field_mapping.py +150 -0
  27. revitdevtool_pytest-0.2.0/tests/schedule/header_workflow.py +43 -0
  28. revitdevtool_pytest-0.2.0/tests/schedule/model.py +54 -0
  29. revitdevtool_pytest-0.2.0/tests/schedule/serializer.py +296 -0
  30. revitdevtool_pytest-0.2.0/tests/schedule/table_cell.py +100 -0
  31. revitdevtool_pytest-0.2.0/tests/schedule/template_workflow.py +210 -0
  32. revitdevtool_pytest-0.2.0/tests/schedule/test.json +1263 -0
  33. revitdevtool_pytest-0.2.0/tests/test_active_state.py +28 -0
  34. revitdevtool_pytest-0.2.0/tests/test_dependencies.py +136 -0
  35. revitdevtool_pytest-0.2.0/tests/test_image_export.py +194 -0
  36. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/tests/test_revit_basic.py +9 -11
  37. revitdevtool_pytest-0.2.0/tests/test_revit_document.py +92 -0
  38. revitdevtool_pytest-0.2.0/tests/test_revit_transactions.py +24 -0
  39. revitdevtool_pytest-0.2.0/tests/test_schedule_custom_copy_revit.py +420 -0
  40. revitdevtool_pytest-0.2.0/tests/test_schedule_field_mapping_revit.py +32 -0
  41. revitdevtool_pytest-0.2.0/tests/test_schedule_header_capture_revit.py +28 -0
  42. revitdevtool_pytest-0.2.0/tests/test_schedule_header_copy_revit.py +96 -0
  43. revitdevtool_pytest-0.2.0/tests/test_scheduleformatting_revit.py +159 -0
  44. revitdevtool_pytest-0.2.0/tests/test_session_cleanliness.py +40 -0
  45. revitdevtool_pytest-0.2.0/tests/test_streaming.py +52 -0
  46. revitdevtool_pytest-0.2.0/uv.lock +178 -0
  47. revitdevtool_pytest-0.0.3/CHANGELOG.md +0 -50
  48. revitdevtool_pytest-0.0.3/PKG-INFO +0 -127
  49. revitdevtool_pytest-0.0.3/README.md +0 -100
  50. revitdevtool_pytest-0.0.3/src/revitdevtool_pytest/bridge.py +0 -127
  51. revitdevtool_pytest-0.0.3/src/revitdevtool_pytest/constants.py +0 -28
  52. revitdevtool_pytest-0.0.3/src/revitdevtool_pytest/models.py +0 -95
  53. revitdevtool_pytest-0.0.3/src/revitdevtool_pytest/plugin.py +0 -202
  54. revitdevtool_pytest-0.0.3/src/revitdevtool_pytest/serializer.py +0 -21
  55. revitdevtool_pytest-0.0.3/tests/conftest.py +0 -21
  56. revitdevtool_pytest-0.0.3/tests/test_revit_transactions.py +0 -41
  57. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/.github/workflows/publish.yml +0 -0
  58. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/LICENSE +0 -0
  59. {revitdevtool_pytest-0.0.3 → revitdevtool_pytest-0.2.0}/tests/test_smoke.py +0 -0
@@ -14,3 +14,5 @@ build/
14
14
  .env
15
15
  .venv/
16
16
  venv/
17
+ .idea/
18
+ .gitnexus
@@ -22,10 +22,4 @@
22
22
  "basedpyright.importStrategy": "useBundled",
23
23
  "basedpyright.analysis.typeCheckingMode": "off",
24
24
  "python.testing.pytestEnabled": true,
25
- "python.testing.pytestArgs": [
26
- "--revit-launch",
27
- "--revit-version=2025",
28
- "--revit-launch-timeout=180",
29
- "tests"
30
- ]
31
25
  }
@@ -0,0 +1,112 @@
1
+ # AGENTS
2
+
3
+ ## Overview
4
+
5
+ This is the pytest client plugin for RevitDevTool. It bridges local pytest with a live Revit process via Named Pipe JSON-RPC.
6
+
7
+ ## Architecture
8
+
9
+ ```
10
+ Local pytest (collect) → Named Pipe → Revit process (PytestRunner.py) → Results → Local pytest (report)
11
+ ```
12
+
13
+ ### Module Map
14
+
15
+ | Module | Role |
16
+ |--------|------|
17
+ | `plugin.py` | Hook orchestrator — lifecycle, options, bridge setup |
18
+ | `connection.py` | Bridge lifecycle — discover, connect, lease, launch |
19
+ | `bridge.py` | Wire protocol — Named Pipe framing, request/response |
20
+ | `discovery.py` | Pipe scan, Revit registry lookup, process launch |
21
+ | `reporting.py` | Map remote CaseResult → pytest TestReport |
22
+ | `suite_leasing.py` | Cross-process Revit instance allocation (file-based) |
23
+ | `suite_lock.py` | Windows mutex for same-suite concurrency guard |
24
+ | `dialog_resolver.py` | Auto-dismiss Revit startup dialogs via Win32 |
25
+ | `models.py` | Wire protocol data models (mirrors C# PytestContracts) |
26
+ | `constants.py` | Shared constants, option names, defaults |
27
+
28
+ ### Revit-Side (in RevitDevTool repo)
29
+
30
+ | File | Role |
31
+ |------|------|
32
+ | `PytestRunner.py` | Embedded script — runs `pytest.main()` inside Revit |
33
+ | `SetupRevit.py` | Runtime setup — API refs, I/O redirection |
34
+ | `PytestExecutionService.cs` | C# orchestrator — receives pipe request, invokes Python |
35
+ | `PytestContracts.cs` | C# wire models (mirrors `models.py`) |
36
+
37
+ ## Key Design Decisions
38
+
39
+ - **Dual pytest model**: Local pytest collects tests; remote pytest executes them. This enables IDE integration (test tree, navigation) while executing in Revit's thread.
40
+ - **`--capture=sys`**: Required because fd-level capture (`os.dup2`) doesn't work in embedded Python.NET.
41
+ - **`--disable-plugin-autoload`**: Prevents third-party plugins from interfering with in-Revit execution.
42
+ - **`sys.__pytest_running__`**: Flag set by PytestRunner to prevent SetupRevit from hijacking stdout/stderr during test runs.
43
+ - **Streaming vs batch**: CLI gets real-time progress notifications; IDE adapters get one batch to avoid double-counting.
44
+ - **Suite leasing**: File-based lease store binds suite → Revit PID across processes. Mutex prevents same-suite parallel runs.
45
+ - **force_launch**: When enabled, spawns new Revit and waits for its exact PID pipe (ignores existing instances).
46
+
47
+ ## Running Tests
48
+
49
+ ```bash
50
+ # From project root with .venv activated:
51
+ pytest
52
+
53
+ # Or via uv / pixi:
54
+ uv run pytest
55
+ pixi run pytest
56
+
57
+ # Specific test:
58
+ pytest tests/test_active_state.py::test_active_view_info -v
59
+ ```
60
+
61
+ Plugin auto-enables `-rP` (show captured stdout for passing tests).
62
+
63
+ ## Configuration
64
+
65
+ All options in `pyproject.toml` under `[tool.pytest.ini_options]`:
66
+
67
+ ```toml
68
+ revit_version = "2025" # Required for launch
69
+ revit_launch = false # true = always spawn new instance
70
+ revit_timeout = "60" # Per-test timeout (seconds)
71
+ revit_launch_timeout = "180" # Startup wait (seconds)
72
+ revit_pipe = "" # Explicit pipe (bypass discovery)
73
+ ```
74
+
75
+ ## Fixtures Pattern
76
+
77
+ ```python
78
+ # conftest.py
79
+ @pytest.fixture(scope="session")
80
+ def revit_uiapp():
81
+ return __revit__ # UIApplication injected by host
82
+
83
+ @pytest.fixture(scope="session")
84
+ def revit_doc(revit_uiapp):
85
+ return revit_uiapp.ActiveUIDocument.Document
86
+
87
+ @pytest.fixture
88
+ def revit_auto_rollback(revit_transaction_service):
89
+ """Start undo tracking, revert after test."""
90
+ revit_transaction_service.StartChanges()
91
+ try:
92
+ yield revit_transaction_service
93
+ finally:
94
+ revit_transaction_service.RevertChanges()
95
+ ```
96
+
97
+ ## Common Traps
98
+
99
+ - Tests execute **inside Revit**, not locally. `import` statements for Revit API (`Autodesk.Revit.DB`) only work at test runtime.
100
+ - `__revit__` is a builtin injected by SetupRevit — always access via fixtures, not direct import.
101
+ - Revit API requires main-thread access. All tests run sequentially via FIFO queue (`IHostContextExecutor`).
102
+ - Named Pipe format: `Revit_{year}_{pid}` (e.g. `Revit_2025_12345`).
103
+ - PEP 723 dependencies in `conftest.py` are auto-installed by `PytestDependencyService` before execution.
104
+ - `force_launch` requires `revit_version` to be set — otherwise exits with config error.
105
+ - Print output inside tests is captured by pytest's `--capture=sys` mechanism and returned via `CaseResult.stdout`.
106
+
107
+ ## Change Rules
108
+
109
+ - Wire protocol changes must update both `models.py` (Python) and `PytestContracts.cs` (C#).
110
+ - Adding CLI options: register in both `pytest_addoption` (CLI) and `parser.addini` (INI).
111
+ - Connection logic is stateless by design — all functions receive parameters, no module-level mutable state except `plugin.py` globals.
112
+ - After modifying connection/discovery logic, manually test with both `revit_launch = true` and `false`.
@@ -0,0 +1,115 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.2.0] - 2026-05-31
6
+
7
+ ### Added
8
+
9
+ - **Auto print capture:** plugin automatically enables `-rP` behavior — captured `print()` output is shown for both passing and failing tests without any user configuration.
10
+ - **PID-aware pipe discovery:** `wait_for_revit_pipe` can now wait for a specific process ID, ensuring `force_launch` connects to the newly spawned instance only.
11
+
12
+ ### Changed
13
+
14
+ - **`revit_launch` → force_launch semantics:** renamed internal parameter from `prefer_fresh` to `force_launch`. When enabled, the plugin disconnects any existing bridge, spawns a new Revit instance, and waits for that exact PID's pipe — never reuses existing instances.
15
+ - **`_opt_bool` fix:** corrected boolean option parsing so `revit_launch = true` in `pyproject.toml` is properly respected when no CLI flag is explicitly passed.
16
+ - **Type annotations refactor:** resolved false-positive IDE warnings across `bridge.py`, `connection.py`, `suite_leasing.py`, and `dialog_resolver.py`.
17
+ - **`SetupRevit.py` (Revit-side):** I/O hijacking is now conditional on `sys.__pytest_running__` flag — prevents conflict with pytest capture during test execution.
18
+ - **`PytestRunner.py` (Revit-side):** sets `sys.__pytest_running__ = True` during execution; top-level error handling wraps entire `_run()` to always return structured JSON.
19
+
20
+ ### Removed
21
+
22
+ - **`discover_tests()`** method from `bridge.py` (client-side dead code; server endpoint remains).
23
+ - **`DiscoverRequest` / `DiscoverResponse`** classes from `models.py` (unused by client).
24
+ - **`BRIDGE_METHOD_TESTS_DISCOVER`** constant (no longer referenced).
25
+ - **`resolve_existing()` / `get_suite_process_id()` / `_prune_stale()`** from `suite_leasing.py` (unused).
26
+ - **`launch_revit()`** from `discovery.py` (replaced by `start_revit` + PID tracking).
27
+ - **`addopts = "-rP"`** from `pyproject.toml` (now automatic via plugin).
28
+
29
+ ### Fixed
30
+
31
+ - **`revit_launch = true` in INI ignored:** `_opt_bool` now correctly reads INI value when CLI flag is not explicitly set.
32
+
33
+ ## [0.1.0] - 2026-05-03
34
+
35
+ ### Added
36
+
37
+ - **Real-time streaming:** test progress notifications streamed from Revit to the pytest client during execution.
38
+ - **Suite leasing:** Windows Mutex-based exclusive access prevents multiple pytest processes from connecting to the same Revit instance.
39
+ - **Test discovery:** `PytestRunRequest` + `_BridgePlugin` integration enables `--collect-only` discovery without executing tests.
40
+ - **Reporting module:** remote `CaseResult[]` mapping back to pytest `TestReport`, with `run_remote_session` orchestrating discover + run.
41
+ - **Connection module:** centralized `ensure_bridge()` with auto-connect, lease management, and Revit auto-launch flow.
42
+ - **Schedule API tests:** comprehensive test suite for Revit schedule operations (copy, field mapping, header, template, custom workflow).
43
+ - **Image export tests:** `test_image_export.py` covering `RevitImageExporter`.
44
+ - **Document & transaction tests:** `test_revit_document.py`, `test_revit_transactions.py`.
45
+ - **Session cleanliness tests:** `test_session_cleanliness.py`, `test_active_state.py` verifying state isolation between runs.
46
+ - **Streaming tests:** `test_streaming.py` validating progress notification flow.
47
+ - **Dependencies tests:** `test_dependencies.py` verifying package resolution.
48
+ - **GitNexus integration:** AGENTS.md, CLAUDE.md, and CLI skills for graph-based code intelligence.
49
+ - **Project setup guide:** recommended `uv` and `pixi` workflows in README.
50
+
51
+ ### Changed
52
+
53
+ - **Architecture rewrite:** `plugin.py` restructured — execution now intercepted via `pytest_runtestloop` instead of `pytest_pyfunc_call`. Remote session orchestrates discover + run in a single round-trip.
54
+ - **Configuration:** primary config via `[tool.pytest.ini_options]` in `pyproject.toml` — CLI flags remain as overrides.
55
+ - **`bridge.py`:** expanded with `discover_tests()`, `run_tests()`, notification dispatch, frame protocol hardening.
56
+ - **`models.py`:** new `DiscoverRequest`, `RunRequest`, `RunResponse`, `CaseResult`, `CollectionError` contracts.
57
+ - **`constants.py`:** centralized all bridge methods, option names, timeouts, pipe patterns.
58
+ - **`pyproject.toml`:** bumped `revit_launch_timeout` to 180s, added `revit_timeout` default.
59
+
60
+ ### Removed
61
+
62
+ - **`serializer.py`:** deprecated — test code serialization replaced by structured discovery + run flow.
63
+ - **`.vscode/settings.json`:** removed from repo; config lives in `pyproject.toml`.
64
+
65
+ ### Notes
66
+
67
+ - `0.1.0` represents a major architectural shift from single-test relay to session-oriented orchestration. The plugin now discovers tests remotely, runs them in batch, and streams progress back in real-time.
68
+ - Suite leasing ensures safe concurrent usage across multiple test suits targeting the same Revit year.
69
+
70
+ ## [0.0.3] - 2026-04-10
71
+
72
+ ### Fixed
73
+
74
+ - Fixed Revit auto-launch dialog handling by starting the startup dialog resolver immediately after spawning Revit, before waiting for the named pipe.
75
+ - Fixed startup dialog button selection to prefer safe allow-list actions such as `Always Load` and `Load Once`.
76
+ - Prevented accidental clicks on destructive dialog actions such as `Do Not Load`, `Cancel`, and `No`.
77
+
78
+ ### Notes
79
+
80
+ - This release focuses on reliable auto-launch behavior when Revit shows unsigned add-in security dialogs during startup.
81
+
82
+ ## [0.0.2] - 2026-04-10
83
+
84
+ ### Fixed
85
+
86
+ - Fixed pytest plugin auto-loading via the `pytest11` entry point.
87
+ - Fixed the `pytest_unconfigure` hook signature in `revitdevtool_pytest.plugin` so Pluggy accepts the plugin during pytest startup.
88
+ - Restored the expected standalone package behavior so `RevitDevTool.PyTest` can be discovered and activated by a normal Python/pytest environment before connecting to Revit.
89
+
90
+ ### Changed
91
+
92
+ - Aligned the published package metadata name with the recommended normalized package name `revitdevtool_pytest`.
93
+
94
+ ### Notes
95
+
96
+ - This release is intended as a bugfix release for the `0.0.1` package.
97
+ - No user-facing CLI options are changed in this release.
98
+ - This name alignment is intended to remain compatible with existing PyPI installs because Python package indexes and installers normalize `.`, `-`, and `_` in distribution names.
99
+
100
+ ## [0.0.1] - 2026-04-09
101
+
102
+ ### Added
103
+
104
+ - Initial standalone `pytest` plugin package for running Revit API tests through the RevitDevTool Named Pipe bridge.
105
+ - Automatic discovery of running Revit instances through named pipes.
106
+ - Optional Revit auto-launch flow via `--revit-launch` and `--revit-version`.
107
+ - Remote test execution by intercepting `pytest_pyfunc_call` and forwarding serialized test code to Revit.
108
+ - Support for explicit pipe targeting with `--revit-pipe`.
109
+ - Per-test timeout and launch timeout configuration.
110
+ - Revit startup dialog resolver integration.
111
+ - Example test suite and VS Code integration guidance in the project documentation.
112
+
113
+ ### Notes
114
+
115
+ - `0.0.1` introduced the core test bridge workflow, but the published package contains a plugin loading issue fixed in `0.0.2`.
@@ -0,0 +1 @@
1
+ Refer to [AGENTS.md](./AGENTS.md) for project rules, conventions, and workflow.
@@ -0,0 +1,193 @@
1
+ Metadata-Version: 2.4
2
+ Name: revitdevtool_pytest
3
+ Version: 0.2.0
4
+ Summary: pytest plugin for testing Revit API code via RevitDevTool Named Pipe bridge
5
+ Project-URL: Homepage, https://github.com/trgiangv/RevitDevTool.PyTest
6
+ Project-URL: Repository, https://github.com/trgiangv/RevitDevTool.PyTest
7
+ Project-URL: Issues, https://github.com/trgiangv/RevitDevTool.PyTest/issues
8
+ Author: Truong Giang Vu
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: bim,pytest,revit,revit-api,revitdevtool,testing
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: Pytest
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Testing
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: pytest>=9.0
25
+ Requires-Dist: pywin32>=311
26
+ Description-Content-Type: text/markdown
27
+
28
+ # RevitDevTool.PyTest
29
+
30
+ [![PyPI version](https://img.shields.io/pypi/v/RevitDevTool.PyTest)](https://pypi.org/project/RevitDevTool.PyTest/)
31
+ [![Python](https://img.shields.io/pypi/pyversions/RevitDevTool.PyTest)](https://pypi.org/project/RevitDevTool.PyTest/)
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
33
+
34
+ pytest plugin for testing Revit API code via RevitDevTool Named Pipe bridge.
35
+ Tests run inside a live Revit process — write standard pytest, execute remotely.
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ pip install revitdevtool_pytest
41
+ ```
42
+
43
+ ## Dependencies
44
+
45
+ | Package | Version |
46
+ |---|---|
47
+ | Python | >= 3.10 |
48
+ | pytest | >= 9.0 |
49
+ | pywin32 | >= 311 |
50
+
51
+ ## Requirements
52
+
53
+ - Windows (Named Pipes)
54
+ - Revit with [RevitDevTool](https://github.com/trgiangv/RevitDevTool) add-in installed and loaded
55
+
56
+ ## Project Setup
57
+
58
+ **Recommended:** scaffold your project with [uv](https://docs.astral.sh/uv/) or [pixi](https://pixi.sh/):
59
+
60
+ ```bash
61
+ # uv
62
+ uv init my-revit-tests
63
+ cd my-revit-tests
64
+ uv add revitdevtool_pytest
65
+
66
+ # pixi (uses pyproject.toml as manifest)
67
+ pixi init --format pyproject my-revit-tests
68
+ cd my-revit-tests
69
+ pixi add --pypi revitdevtool_pytest
70
+ ```
71
+
72
+ ## Configuration
73
+
74
+ Add plugin settings to `[tool.pytest.ini_options]` in your `pyproject.toml`:
75
+
76
+ ```toml
77
+ [tool.pytest.ini_options]
78
+ revit_version = "2025"
79
+ revit_launch = false
80
+ revit_launch_timeout = "180"
81
+ ```
82
+
83
+ | Option | Type | Default | Description |
84
+ |---|---|---|---|
85
+ | `revit_version` | string | — | Revit version year (e.g. `"2025"`). Required when `revit_launch = true`. |
86
+ | `revit_launch` | bool | `false` | Force-launch a **new** Revit instance (skip reusing existing free instances). |
87
+ | `revit_timeout` | string | `"60"` | Per-test execution timeout in seconds. |
88
+ | `revit_launch_timeout` | string | `"120"` | Seconds to wait for Revit to start. |
89
+ | `revit_pipe` | string | — | Explicit pipe name (bypasses auto-discovery). |
90
+
91
+ CLI flags override INI settings:
92
+
93
+ ```bash
94
+ pytest --revit-launch --revit-version=2025 -v
95
+ ```
96
+
97
+ ### Connection Behavior
98
+
99
+ - **Default** (`revit_launch = false`): plugin auto-discovers a running Revit instance matching `revit_version` via Named Pipe scan. If none found, exits with error.
100
+ - **Force launch** (`revit_launch = true`): always spawns a new Revit process, waits for its pipe to appear, then connects. Existing instances are ignored.
101
+
102
+ ### Print Output
103
+
104
+ Captured `print()` output from tests running inside Revit is automatically shown in the terminal for passing tests (equivalent to `-rP`). No extra flags needed.
105
+
106
+ ## Usage
107
+
108
+ ### Fixtures
109
+
110
+ Define fixtures in `conftest.py` that provide Revit API objects:
111
+
112
+ ```python
113
+ import pytest
114
+
115
+ @pytest.fixture(scope="session")
116
+ def revit_uiapp():
117
+ return __revit__ # UIApplication injected by RevitDevTool
118
+
119
+ @pytest.fixture(scope="session")
120
+ def revit_app(revit_uiapp):
121
+ return revit_uiapp.Application
122
+
123
+ @pytest.fixture(scope="session")
124
+ def revit_doc(revit_uiapp):
125
+ return revit_uiapp.ActiveUIDocument.Document
126
+ ```
127
+
128
+ ### Writing Tests
129
+
130
+ ```python
131
+ def test_active_view(revit_doc):
132
+ view = revit_doc.ActiveView
133
+ print(f"Active View: {view.Name}")
134
+ assert view.Name is not None
135
+
136
+ def test_revit_version(revit_app):
137
+ assert "2025" in revit_app.VersionName
138
+ ```
139
+
140
+ ### PEP 723 Dependencies
141
+
142
+ Declare test-suite dependencies in `conftest.py` using PEP 723 metadata. RevitDevTool auto-installs them before test execution:
143
+
144
+ ```python
145
+ # /// script
146
+ # dependencies = [
147
+ # "numpy>=2.0",
148
+ # "polars>=1.0",
149
+ # ]
150
+ # ///
151
+ ```
152
+
153
+ ### Running Tests
154
+
155
+ ```bash
156
+ # With pyproject.toml configured:
157
+ pytest
158
+
159
+ # Override version for a single run:
160
+ pytest --revit-version=2026 -v
161
+
162
+ # Using uv or pixi:
163
+ uv run pytest
164
+ pixi run pytest
165
+ ```
166
+
167
+ ## How It Works
168
+
169
+ 1. pytest discovers and collects tests locally
170
+ 2. Plugin intercepts `pytest_runtestloop`, connects to Revit via Named Pipe
171
+ 3. Test nodeids are sent to Revit's `PytestRunner.py` (embedded in RevitDevTool)
172
+ 4. Tests execute inside Revit's Python.NET environment with full API access
173
+ 5. Results (pass/fail/skip, stdout, stderr, tracebacks) are returned via pipe
174
+ 6. Plugin maps results back to standard pytest reports
175
+
176
+ ## IDE Integration
177
+
178
+ ### VS Code / Cursor
179
+
180
+ ```json
181
+ {
182
+ "python.testing.pytestEnabled": true,
183
+ "python.testing.pytestArgs": ["tests"]
184
+ }
185
+ ```
186
+
187
+ ### PyCharm
188
+
189
+ Enable pytest as the test runner. Plugin auto-detects IDE adapters and disables streaming to avoid duplicate results in the test tree.
190
+
191
+ ## License
192
+
193
+ [MIT](LICENSE)
@@ -0,0 +1,166 @@
1
+ # RevitDevTool.PyTest
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/RevitDevTool.PyTest)](https://pypi.org/project/RevitDevTool.PyTest/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/RevitDevTool.PyTest)](https://pypi.org/project/RevitDevTool.PyTest/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ pytest plugin for testing Revit API code via RevitDevTool Named Pipe bridge.
8
+ Tests run inside a live Revit process — write standard pytest, execute remotely.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pip install revitdevtool_pytest
14
+ ```
15
+
16
+ ## Dependencies
17
+
18
+ | Package | Version |
19
+ |---|---|
20
+ | Python | >= 3.10 |
21
+ | pytest | >= 9.0 |
22
+ | pywin32 | >= 311 |
23
+
24
+ ## Requirements
25
+
26
+ - Windows (Named Pipes)
27
+ - Revit with [RevitDevTool](https://github.com/trgiangv/RevitDevTool) add-in installed and loaded
28
+
29
+ ## Project Setup
30
+
31
+ **Recommended:** scaffold your project with [uv](https://docs.astral.sh/uv/) or [pixi](https://pixi.sh/):
32
+
33
+ ```bash
34
+ # uv
35
+ uv init my-revit-tests
36
+ cd my-revit-tests
37
+ uv add revitdevtool_pytest
38
+
39
+ # pixi (uses pyproject.toml as manifest)
40
+ pixi init --format pyproject my-revit-tests
41
+ cd my-revit-tests
42
+ pixi add --pypi revitdevtool_pytest
43
+ ```
44
+
45
+ ## Configuration
46
+
47
+ Add plugin settings to `[tool.pytest.ini_options]` in your `pyproject.toml`:
48
+
49
+ ```toml
50
+ [tool.pytest.ini_options]
51
+ revit_version = "2025"
52
+ revit_launch = false
53
+ revit_launch_timeout = "180"
54
+ ```
55
+
56
+ | Option | Type | Default | Description |
57
+ |---|---|---|---|
58
+ | `revit_version` | string | — | Revit version year (e.g. `"2025"`). Required when `revit_launch = true`. |
59
+ | `revit_launch` | bool | `false` | Force-launch a **new** Revit instance (skip reusing existing free instances). |
60
+ | `revit_timeout` | string | `"60"` | Per-test execution timeout in seconds. |
61
+ | `revit_launch_timeout` | string | `"120"` | Seconds to wait for Revit to start. |
62
+ | `revit_pipe` | string | — | Explicit pipe name (bypasses auto-discovery). |
63
+
64
+ CLI flags override INI settings:
65
+
66
+ ```bash
67
+ pytest --revit-launch --revit-version=2025 -v
68
+ ```
69
+
70
+ ### Connection Behavior
71
+
72
+ - **Default** (`revit_launch = false`): plugin auto-discovers a running Revit instance matching `revit_version` via Named Pipe scan. If none found, exits with error.
73
+ - **Force launch** (`revit_launch = true`): always spawns a new Revit process, waits for its pipe to appear, then connects. Existing instances are ignored.
74
+
75
+ ### Print Output
76
+
77
+ Captured `print()` output from tests running inside Revit is automatically shown in the terminal for passing tests (equivalent to `-rP`). No extra flags needed.
78
+
79
+ ## Usage
80
+
81
+ ### Fixtures
82
+
83
+ Define fixtures in `conftest.py` that provide Revit API objects:
84
+
85
+ ```python
86
+ import pytest
87
+
88
+ @pytest.fixture(scope="session")
89
+ def revit_uiapp():
90
+ return __revit__ # UIApplication injected by RevitDevTool
91
+
92
+ @pytest.fixture(scope="session")
93
+ def revit_app(revit_uiapp):
94
+ return revit_uiapp.Application
95
+
96
+ @pytest.fixture(scope="session")
97
+ def revit_doc(revit_uiapp):
98
+ return revit_uiapp.ActiveUIDocument.Document
99
+ ```
100
+
101
+ ### Writing Tests
102
+
103
+ ```python
104
+ def test_active_view(revit_doc):
105
+ view = revit_doc.ActiveView
106
+ print(f"Active View: {view.Name}")
107
+ assert view.Name is not None
108
+
109
+ def test_revit_version(revit_app):
110
+ assert "2025" in revit_app.VersionName
111
+ ```
112
+
113
+ ### PEP 723 Dependencies
114
+
115
+ Declare test-suite dependencies in `conftest.py` using PEP 723 metadata. RevitDevTool auto-installs them before test execution:
116
+
117
+ ```python
118
+ # /// script
119
+ # dependencies = [
120
+ # "numpy>=2.0",
121
+ # "polars>=1.0",
122
+ # ]
123
+ # ///
124
+ ```
125
+
126
+ ### Running Tests
127
+
128
+ ```bash
129
+ # With pyproject.toml configured:
130
+ pytest
131
+
132
+ # Override version for a single run:
133
+ pytest --revit-version=2026 -v
134
+
135
+ # Using uv or pixi:
136
+ uv run pytest
137
+ pixi run pytest
138
+ ```
139
+
140
+ ## How It Works
141
+
142
+ 1. pytest discovers and collects tests locally
143
+ 2. Plugin intercepts `pytest_runtestloop`, connects to Revit via Named Pipe
144
+ 3. Test nodeids are sent to Revit's `PytestRunner.py` (embedded in RevitDevTool)
145
+ 4. Tests execute inside Revit's Python.NET environment with full API access
146
+ 5. Results (pass/fail/skip, stdout, stderr, tracebacks) are returned via pipe
147
+ 6. Plugin maps results back to standard pytest reports
148
+
149
+ ## IDE Integration
150
+
151
+ ### VS Code / Cursor
152
+
153
+ ```json
154
+ {
155
+ "python.testing.pytestEnabled": true,
156
+ "python.testing.pytestArgs": ["tests"]
157
+ }
158
+ ```
159
+
160
+ ### PyCharm
161
+
162
+ Enable pytest as the test runner. Plugin auto-detects IDE adapters and disables streaming to avoid duplicate results in the test tree.
163
+
164
+ ## License
165
+
166
+ [MIT](LICENSE)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "revitdevtool_pytest"
7
- version = "0.0.3"
7
+ version = "0.2.0"
8
8
  description = "pytest plugin for testing Revit API code via RevitDevTool Named Pipe bridge"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -36,3 +36,10 @@ Issues = "https://github.com/trgiangv/RevitDevTool.PyTest/issues"
36
36
 
37
37
  [tool.hatch.build.targets.wheel]
38
38
  packages = ["src/revitdevtool_pytest"]
39
+
40
+ [tool.pytest.ini_options]
41
+ testpaths = ["tests"]
42
+ revit_version = "2025"
43
+ revit_timeout = "60"
44
+ revit_launch = false
45
+ revit_launch_timeout = "180"
@@ -1,3 +1,3 @@
1
1
  """RevitDevTool.PyTest: Run pytest tests inside a live Revit process via Named Pipe bridge."""
2
2
 
3
- __version__ = "0.0.1"
3
+ __version__ = "0.2.0"