Index of every page on this site: llms.txt
All skills
kaushik-holla avatar

/python-quality

@cb7c214
Run it yourself

Standard Python project setup and quality gates using uv (or conda + pip), src-layout, ruff (lint + format), mypy strict, pytest 9 + pytest-asyncio, pre-commit, and GitHub Actions with setup-uv. Ships pyproject.toml, pre-commit, CI, .env, and environment.yml templates, a one-command quality gate script, and LLM-friendly test patterns. Use when scaffolding a new Python project, upgrading older tooling (pip/poetry/black/flake8/isort) to the uv + ruff stack, adding CI, or setting up tests for an agentic or LLM project.

  • 8 files
  • 21.9 KB
  • MIT
  • Updated 4 days ago
  • GitHub
Use this Skill: https://skilld.dev/gh/kaushik-holla/agent-skills/python-quality

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestesting-patterns.md

≈781 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Testing Patterns for Agentic / LLM Python Projects

Loaded on demand from the python-quality skill. myapp is a placeholder package name.

Layout

tests/
  conftest.py          # shared fixtures
  unit/
    test_state.py
    test_routers.py
    test_clarity_node.py
  integration/
    test_graph_happy_path.py
    test_validator_loop.py
    test_interrupt_resume.py
  eval/
    test_synthesis_quality.py   # marked @pytest.mark.eval

Mock the LLM at the boundary

Patch the provider (the chat-model object your node calls), not your own function.

from unittest.mock import MagicMock

import pytest


@pytest.fixture
def fake_clarity_model() -> MagicMock:
    """A chat-model-shaped mock whose `.invoke` returns a Pydantic decision."""
    from myapp.agents.clarity import ClarityDecision

    m = MagicMock()
    m.invoke.return_value = ClarityDecision(status="clear", reason="company named")
    return m


def test_clarity_node_clear(monkeypatch: pytest.MonkeyPatch, fake_clarity_model: MagicMock) -> None:
    from myapp.agents import clarity

    monkeypatch.setattr(clarity, "clarity_model", fake_clarity_model)
    out = clarity.clarity_node({"messages": [...], "attempts": 0})
    assert out["clarity_status"] == "clear"

For free-text responses, LangChain ships a real fake model that behaves like a chat model (streaming, callbacks, tracing) without network calls:

from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage

fake = GenericFakeChatModel(messages=iter([AIMessage(content="Acme Corp is ...")]))

Deterministic fixtures

import pytest
from langchain_core.messages import HumanMessage


@pytest.fixture
def fixed_company_query() -> list[HumanMessage]:
    return [HumanMessage(content="Tell me about Acme Corp")]

Marker-gated live LLM tests

import pytest


@pytest.mark.live_llm
def test_real_clarity_call(real_settings) -> None:
    # Only runs with: uv run pytest -m live_llm
    ...

Settings isolation

Never let a developer's real .env leak into tests. Build Settings explicitly in a fixture:

import pytest

from myapp.config import Settings


@pytest.fixture
def settings(monkeypatch: pytest.MonkeyPatch) -> Settings:
    monkeypatch.delenv("OPENAI_API_KEY", raising=False)
    return Settings(_env_file=None, LLM_MODEL="openai:test-model", SEARCH_PROVIDER="mock")

No time.sleep in tests

Use pytest-asyncio time control, or refactor the code to take a clock dependency, rather than sleeping in tests. Sleeps make CI flaky.

Async tests

With asyncio_mode = "auto" (see assets/pyproject.toml), plain async def test_... functions run on an event loop without a decorator. Keep asyncio_default_fixture_loop_scope = "function" so each test gets an isolated loop unless a fixture explicitly asks for a wider scope.

Graph-level tests

For LangGraph-specific testing (checkpointed threads, interrupt/resume round-trips, router coverage), see the langgraph-patterns skill's references/testing.md.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at cb7c214. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 4 days ago
metadata
{
  "author": "kaushik-holla",
  "version": "2.0"
}

README badge

README badge for kaushik-holla/agent-skills/python-quality