agentleFS
sagar-shirwalkarsagar-shirwalkar/servicenow-atlas/.agents/skills/python-testing-patterns/SKILL.md

python-testing-patterns

Skill2 starsChanged 5 months agoApache-2.0View on GitHub

Test conventions for the atlas project: pytest setup, fixture patterns, mocking external dependencies, and smoke test patterns. Use when writing new tests, setting up test infrastructure, or debugging a test failure.

30 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use docs-ci, docs-interfaces and 6 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • jh941213Skill

    docs-ci

    문서 CI(링크·OpenAPI lint·breaking 게이트·mermaid 검증)나 문서 드리프트 감지(docs.yaml 신선도 검사)를 설치하거나 돌릴 때 사용. 문서 내용 작성은 docs-architecture·docs-interfaces·docs-manuals.

    Also in 3 projects that use this

  • jh941213Skill

    docs-interfaces

    API·이벤트 인터페이스 문서(OpenAPI·swagger·AsyncAPI 명세, 엔드포인트 레퍼런스, API 구성도·시퀀스, API CHANGELOG)를 만들거나 코드와 맞출 때 사용. 시스템 구성도는 docs-architecture, API 설계 원칙은 api-design-principles.

    Also in 3 projects that use this

  • Aver005Skill

    python-resource-management

    Python resource management with context managers, cleanup patterns, and streaming. Use when managing connections, file handles, implementing cleanup logic, or building streaming responses with accumulated state.

    Also in 4 projects that use this

  • Aver005Skill

    python-design-patterns

    Python design patterns including KISS, Separation of Concerns, Single Responsibility, and composition over inheritance. Use when making architecture decisions, refactoring code structure, or evaluating when abstractions are appropriate.

    Also in 6 projects that use this

  • +4 more from jh941213

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 0 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 29 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use conftest.py for shared fixtures.

    line 40
  2. Very specific:

    Test write_manifest with and without embedding_dim.

    line 98
  3. Very specific:

    Test write_chunks with sample chunk data.

    line 99
  4. Very specific:

    Test Embedder base class contract (ABC).

    line 104
  5. Very specific:

    Test OnnxEmbedder model resolution: snapshot_download path.

    line 105
  6. Very specific:

    Test dim property from ONNX model shape.

    line 106
  7. Very specific:

    Test MlxEmbedder zero-vector fallback.

    line 107

“Common” is measured: kept by at least 6 in 10 of the 29 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

When to use

  • Writing unit or integration tests for the project
  • Setting up test infrastructure (conftest.py, fixtures)
  • Adding tests for a new module
  • Debugging a failing test

Prerequisites

Tests require the dev dependencies:

uv sync --extra dev

Test structure

Tests live in tests/ at the project root, mirroring atlas/:

tests/
├── conftest.py          # Shared fixtures
├── test_chunk.py        # Tests for atlas/chunk.py
├── test_make_bundle.py  # Tests for atlas/make_bundle.py
└── test_embed/
    ├── conftest.py      # Embedder fixtures
    └── test_onnx.py     # Tests for atlas/embed/onnx.py

Fixture patterns

Use conftest.py for shared fixtures. Keep them scoped appropriately.

tests/conftest.py

from __future__ import annotations

from collections.abc import Generator
from pathlib import Path
import tempfile

import pytest


@pytest.fixture
def tmp_bundle_dir() -> Generator[Path, None, None]:
    """Provide a temporary directory for bundle output."""
    with tempfile.TemporaryDirectory() as d:
        yield Path(d)

Mocking external dependencies

For tests that should not hit Hugging Face or the network:

@pytest.fixture(autouse=True)
def mock_hf_download(monkeypatch: pytest.MonkeyPatch) -> None:
    """Prevent accidental network calls during tests."""

    def fake_download(*args, **kwargs) -> str:
        return "/tmp/fake-model-dir"

    monkeypatch.setattr(
        "huggingface_hub.snapshot_download",
        fake_download,
    )

For tests that need real ONNX inference, mark them as integration:

@pytest.mark.integration
def test_onnx_embedder_inference(onnx_embedder: OnnxEmbedder) -> None:
    embeddings = onnx_embedder.embed(["hello world"])
    assert embeddings.shape[1] == onnx_embedder.dim

Test patterns by module

atlas/chunk.py

  • Unit test parse_frontmatter with: valid YAML, malformed YAML, no frontmatter, empty file.
  • Unit test _split_on_h2 with: normal headings, no headings, consecutive headings, heading at EOF.
  • Integration test chunk_file against a real markdown file in tests/fixtures/.

atlas/make_bundle.py

  • Test write_manifest with and without embedding_dim.
  • Test write_chunks with sample chunk data.
  • Integration test: build a bundle from tests/fixtures/ docs and verify outputs.

atlas/embed/

  • Test Embedder base class contract (ABC).
  • Test OnnxEmbedder model resolution: snapshot_download path.
  • Test dim property from ONNX model shape.
  • Test MlxEmbedder zero-vector fallback.
  • Mark GPU tests as @pytest.mark.gpu (skipped when no GPU).

Coverage

  • Target: 80%+ for utility modules (chunk.py, make_bundle.py).
  • Core embedding paths: integration tests only (too costly to unit-test inference).
  • Smoke test (atlas-smoke): always runs end-to-end, never mocked — this is the CI gate.

Running tests

# All non-integration tests (fast)
uv run pytest -m "not integration and not gpu"

# Integration tests (requires model download)
uv run pytest -m integration

# Full suite
uv run pytest

References

  • atlas/smoke_test.py — the end-to-end smoke test pattern
  • README.md §7 — testing roadmap
  • pyproject.toml — dev dependency (pytest>=8.0)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.