Skip to content

[FIX]: Avoid eager PyRIT imports during pytest startup - #173

Merged
Spencer Schoenberg (spencrr) merged 1 commit into
microsoft:mainfrom
spencrr:dev/spencer/perf-pytester-startup
Aug 24, 2026
Merged

[FIX]: Avoid eager PyRIT imports during pytest startup#173
Spencer Schoenberg (spencrr) merged 1 commit into
microsoft:mainfrom
spencrr:dev/spencer/perf-pytester-startup

Conversation

@spencrr

Copy link
Copy Markdown
Contributor

Description

Avoid eagerly importing PyRIT and Transformers when pytest loads the RAMPART plugin.

  • Lazily resolve PyRIT-backed top-level exports using PEP 562.
  • Preserve the existing public API and static type information.
  • Add regression tests for lightweight plugin startup and lazy export caching.

Performance:

  • Plugin import: 15.77s -> 0.49s
  • Representative pytester tests: 48.50s -> 9.66s
  • All 19 pytester tests complete in 181.56 ->19.01s

Validation:

  • pre-commit run --all-files
  • Full unit suite: 714 passed

Breaking changes

None.

Checklist

  • pre-commit run --all-files passes
  • Tests added or updated for changes
  • Documentation updated (not required; no user-facing API change)

@spencrr
Spencer Schoenberg (spencrr) requested review from a team and a balanced review from Copilot August 24, 2026 18:20
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Defers PyRIT-backed exports to reduce RAMPART pytest plugin startup time while preserving the public API.

Changes:

  • Adds PEP 562 lazy loading and caching for heavy exports.
  • Adds regression tests for lightweight startup and lazy resolution.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rampart/__init__.py Lazily resolves PyRIT-backed exports.
tests/unit/test_public_api.py Tests startup imports and export caching.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/unit/test_public_api.py
Comment thread rampart/__init__.py
Comment thread rampart/__init__.py
Comment thread rampart/__init__.py
@spencrr
Spencer Schoenberg (spencrr) merged commit 68641d5 into microsoft:main Aug 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants