From 0637e2b8c9ba8b01288303b5983304a7e22395ca Mon Sep 17 00:00:00 2001 From: Jonas Lundberg Date: Fri, 21 Jul 2023 00:05:06 +0200 Subject: [PATCH] Document manual triggering of Router `assert_all_called` (#241) --- .github/workflows/check-docs.yml | 20 +++++++++++++++++++ .github/workflows/lint.yml | 9 +++++++++ .../workflows/{docs.yml => publish-docs.yml} | 2 +- .github/workflows/test.yml | 20 ++++--------------- docs/guide.md | 13 ++++++++++-- 5 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/check-docs.yml create mode 100644 .github/workflows/lint.yml rename .github/workflows/{docs.yml => publish-docs.yml} (97%) diff --git a/.github/workflows/check-docs.yml b/.github/workflows/check-docs.yml new file mode 100644 index 0000000..41f9444 --- /dev/null +++ b/.github/workflows/check-docs.yml @@ -0,0 +1,20 @@ +name: check-docs + +on: + pull_request: + paths: + - 'docs/**' + - '.github/workflows/check-docs.yml' + +jobs: + check-docs: + name: Check Docs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - run: pip install nox + - name: Run mypy + run: nox -N -s docs diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..681d5ee --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,9 @@ +name: lint + +on: + pull_request: + +jobs: + lint: + name: Check Linting + uses: less-action/reusables/.github/workflows/pre-commit.yaml@v8 diff --git a/.github/workflows/docs.yml b/.github/workflows/publish-docs.yml similarity index 97% rename from .github/workflows/docs.yml rename to .github/workflows/publish-docs.yml index cb5303d..18efb2b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/publish-docs.yml @@ -1,4 +1,4 @@ -name: docs +name: publish-docs on: push: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2b23c8..788c2e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,11 @@ on: push: branches: - master + paths-ignore: + - 'docs/**' pull_request: + paths-ignore: + - 'docs/**' env: FORCE_COLOR: 1 @@ -33,10 +37,6 @@ jobs: files: ./coverage.xml fail_ci_if_error: true - lint: - name: Check Linting - uses: less-action/reusables/.github/workflows/pre-commit.yaml@v8 - check-types: name: Check Typing runs-on: ubuntu-latest @@ -48,15 +48,3 @@ jobs: - run: pip install nox - name: Run mypy run: nox -N -s mypy - - check-docs: - name: Check Docs - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - run: pip install nox - - name: Run mypy - run: nox -N -s docs diff --git a/docs/guide.md b/docs/guide.md index e033afd..da8bfe7 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -623,7 +623,6 @@ If you don't *need* to patch `HTTPX`, use `httpx.MockTransport` with a REPX rout ``` python import httpx import respx -from respx.transports import MockTransport router = respx.Router() @@ -635,10 +634,20 @@ def test_client(): with httpx.Client(transport=mock_transport) as client: response = client.post("https://example.org/") assert response.status_code == 404 + + +def test_client(): + mock_transport = httpx.MockTransport(router.async_handler) + with httpx.AsyncClient(transport=mock_transport) as client: + ... ``` + !!! note "NOTE" - Use `httpx.MockTransport(router.async_handler)` when using an `httpx.AsyncClient`. + To assert all routes is called, you'll need to trigger + `.assert_all_called()` manually, e.g. in a test case or after yielding the + router in a *pytest* fixture, since there's no auto post assertion done like + when using [respx.mock](#assert-all-called). !!! Hint You can use `RESPX` not only to mock out `HTTPX`, but actually mock any library using `HTTP Core` transports.