pytest-asyncio-httpx-mocking

Community

Mock async HTTP calls in Pytest with AsyncMock.

AuthorStarrySerendipity
Version1.0.0
Installs0

System Documentation

What problem does it solve?

Using unittest.mock.patch on httpx.AsyncClient to mock async methods like post/get often returns a non-awaitable MagicMock, causing TypeError when awaited. This Skill guides you to use AsyncMock for async methods to ensure proper coroutine behavior and avoid await errors.

Core Features & Use Cases

  • Correctly patch AsyncClient methods (post/get) with AsyncMock to produce awaitable responses.
  • Explain the distinction between AsyncMock (async) and MagicMock (sync) and provide representative test scenarios.
  • Real-world use: test a PyTest data fetcher that awaits httpx AsyncClient responses without flakiness.

Quick Start

Patch httpx.AsyncClient.post (and get) with AsyncMock in your pytest tests to ensure awaitable responses.

Dependency Matrix

Required Modules

None required

Components

Standard package

💻 Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: pytest-asyncio-httpx-mocking
Download link: https://github.com/StarrySerendipity/N.E.K.O/archive/main.zip#pytest-asyncio-httpx-mocking

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 510,000+ vetted skills library on demand.