Skip to content

Commit

Permalink
Document manual triggering of Router assert_all_called (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
lundberg committed Jul 20, 2023
1 parent 06a534d commit 0637e2b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/check-docs.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: lint

on:
pull_request:

jobs:
lint:
name: Check Linting
uses: less-action/reusables/.github/workflows/pre-commit.yaml@v8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: docs
name: publish-docs

on:
push:
Expand Down
20 changes: 4 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ on:
push:
branches:
- master
paths-ignore:
- 'docs/**'
pull_request:
paths-ignore:
- 'docs/**'

env:
FORCE_COLOR: 1
Expand Down Expand Up @@ -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
Expand All @@ -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
13 changes: 11 additions & 2 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
`<router>.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.
Expand Down

0 comments on commit 0637e2b

Please sign in to comment.