Skip to content

Commit 0637e2b

Browse files
authored
Document manual triggering of Router assert_all_called (#241)
1 parent 06a534d commit 0637e2b

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

.github/workflows/check-docs.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: check-docs
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'docs/**'
7+
- '.github/workflows/check-docs.yml'
8+
9+
jobs:
10+
check-docs:
11+
name: Check Docs
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-python@v4
16+
with:
17+
python-version: "3.10"
18+
- run: pip install nox
19+
- name: Run mypy
20+
run: nox -N -s docs

.github/workflows/lint.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: lint
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
lint:
8+
name: Check Linting
9+
uses: less-action/reusables/.github/workflows/pre-commit.yaml@v8

.github/workflows/docs.yml renamed to .github/workflows/publish-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: docs
1+
name: publish-docs
22

33
on:
44
push:

.github/workflows/test.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ on:
44
push:
55
branches:
66
- master
7+
paths-ignore:
8+
- 'docs/**'
79
pull_request:
10+
paths-ignore:
11+
- 'docs/**'
812

913
env:
1014
FORCE_COLOR: 1
@@ -33,10 +37,6 @@ jobs:
3337
files: ./coverage.xml
3438
fail_ci_if_error: true
3539

36-
lint:
37-
name: Check Linting
38-
uses: less-action/reusables/.github/workflows/pre-commit.yaml@v8
39-
4040
check-types:
4141
name: Check Typing
4242
runs-on: ubuntu-latest
@@ -48,15 +48,3 @@ jobs:
4848
- run: pip install nox
4949
- name: Run mypy
5050
run: nox -N -s mypy
51-
52-
check-docs:
53-
name: Check Docs
54-
runs-on: ubuntu-latest
55-
steps:
56-
- uses: actions/checkout@v3
57-
- uses: actions/setup-python@v4
58-
with:
59-
python-version: "3.10"
60-
- run: pip install nox
61-
- name: Run mypy
62-
run: nox -N -s docs

docs/guide.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ If you don't *need* to patch `HTTPX`, use `httpx.MockTransport` with a REPX rout
623623
``` python
624624
import httpx
625625
import respx
626-
from respx.transports import MockTransport
627626

628627

629628
router = respx.Router()
@@ -635,10 +634,20 @@ def test_client():
635634
with httpx.Client(transport=mock_transport) as client:
636635
response = client.post("https://example.org/")
637636
assert response.status_code == 404
637+
638+
639+
def test_client():
640+
mock_transport = httpx.MockTransport(router.async_handler)
641+
with httpx.AsyncClient(transport=mock_transport) as client:
642+
...
638643
```
639644

645+
640646
!!! note "NOTE"
641-
Use `httpx.MockTransport(router.async_handler)` when using an `httpx.AsyncClient`.
647+
To assert all routes is called, you'll need to trigger
648+
`<router>.assert_all_called()` manually, e.g. in a test case or after yielding the
649+
router in a *pytest* fixture, since there's no auto post assertion done like
650+
when using [respx.mock](#assert-all-called).
642651

643652
!!! Hint
644653
You can use `RESPX` not only to mock out `HTTPX`, but actually mock any library using `HTTP Core` transports.

0 commit comments

Comments
 (0)