Skip to main content

RESPX-like HTTP mocking for niquests

Project description

niquests-mock

CI PyPI Python License

RESPX-style HTTP mocking for niquests.

Usage

Fixture Style

This is the closest workflow to respx_mock in pytest.

import niquests


def test_fixture_style(niquests_mock):
    route = niquests_mock.get("https://example.org/")
    route.respond(status_code=200)

    response = niquests.get("https://example.org/")

    assert route.called
    assert response.status_code == 200

The plugin also exposes respx_mock as a compatibility alias for easier migration from respx.

Development

uv sync --dev
just check

Publishing

PyPI publishing is configured through GitHub Actions with trusted publishing on version tags like v0.1.1. Recommended flow:

  1. Run the manual Publish TestPyPI workflow.
  2. Install and smoke-test the package from TestPyPI.
  3. Push a release tag like v0.1.1.
  4. The publish workflow verifies the tag matches pyproject.toml, runs checks, publishes to PyPI, and creates a GitHub Release.

Before the first release, configure the PyPI and TestPyPI projects, GitHub environments, and trusted publishers.

Decorator Style

Useful when you want the test to look almost exactly like a respx-based test.

import niquests
import niquests_mock as nmock


@nmock.mock
def test_decorator_style():
    route = nmock.get("https://example.org/", name="homepage").respond(status_code=200)
    response = niquests.get("https://example.org/")

    route.assert_called_once()
    assert nmock.lookup("homepage") is route
    assert response.status_code == 200

Decorator factory arguments work too:

import niquests
import niquests_mock as nmock


@nmock.mock(assert_all_called=True, base_url="https://api.example.test")
def test_strict_routes():
    nmock.get("/health", name="health").respond(status_code=200)

    response = niquests.get("https://api.example.test/health")

    assert response.status_code == 200

Context Manager Style

Best when you want explicit router lifetime inside the test body.

import niquests
from niquests_mock import MockRouter


def test_context_manager():
    with MockRouter(base_url="https://api.example.test") as router:
        users = router.get("/users", name="users.list").respond(
            status_code=200,
            json=[{"id": 1, "name": "Ada"}],
        )

        response = niquests.get("https://api.example.test/users")

    assert router["users.list"] is users
    users.assert_called_once()
    assert response.json() == [{"id": 1, "name": "Ada"}]

Project Status

Currently in dev.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

niquests_mock-0.1.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

niquests_mock-0.1.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file niquests_mock-0.1.1.tar.gz.

File metadata

  • Download URL: niquests_mock-0.1.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for niquests_mock-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a4a14b05c0b75b56bb840e731ff581e82bc3c77515c304a5d81b6d1fe74aa7fa
MD5 99f6ab53f3c61f048a0e2c4348bfd567
BLAKE2b-256 bcbfa1415f2655a5434c46085354014e326cdabf62d289cfba80271e87dac68d

See more details on using hashes here.

File details

Details for the file niquests_mock-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: niquests_mock-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for niquests_mock-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e7e4eae9d925a5ace3f9fb86c935560bbc6284c5e1cab2c6a15e54d7efce07b
MD5 1b1861ea7df49f1dbaedf7859b853545
BLAKE2b-256 b872d897c119d8d7a54105b8b5acb43c4d8d9f90452e73ce2696ca27fc8a0cb0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page