Skip to content

Commit

Permalink
Explain how to use the mark on the whole test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin-b committed Sep 23, 2024
1 parent 75c308e commit 549622b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ This behavior can be disabled thanks to the `httpx_mock` marker:
```python
import pytest

# For the whole test suite, to add to the root conftest.py file
def pytest_collection_modifyitems(session, config, items):
for item in items:
item.add_marker(pytest.mark.httpx_mock(assert_all_responses_were_requested=False))

# For whole module
pytestmark = pytest.mark.httpx_mock(assert_all_responses_were_requested=False)

Expand Down Expand Up @@ -465,6 +470,11 @@ This behavior can be disabled thanks to the `httpx_mock` marker:
```python
import pytest

# For the whole test suite, to add to the root conftest.py file
def pytest_collection_modifyitems(session, config, items):
for item in items:
item.add_marker(pytest.mark.httpx_mock(assert_all_responses_were_requested=False))

# For whole module
pytestmark = pytest.mark.httpx_mock(assert_all_responses_were_requested=False)

Expand Down Expand Up @@ -578,6 +588,11 @@ Note that default behavior is to assert that all requests were expected. You can
```python
import pytest

# For the whole test suite, to add to the root conftest.py file
def pytest_collection_modifyitems(session, config, items):
for item in items:
item.add_marker(pytest.mark.httpx_mock(assert_all_requests_were_expected=False))

# For whole module
pytestmark = pytest.mark.httpx_mock(assert_all_requests_were_expected=False)

Expand Down Expand Up @@ -678,6 +693,11 @@ To do so, you can use the `httpx_mock` marker:
```python
import pytest

# For the whole test suite, to add to the root conftest.py file
def pytest_collection_modifyitems(session, config, items):
for item in items:
item.add_marker(pytest.mark.httpx_mock(non_mocked_hosts=["my_local_test_host"]))

# For whole module
pytestmark = pytest.mark.httpx_mock(non_mocked_hosts=["my_local_test_host", "my_other_test_host"])

Expand Down

0 comments on commit 549622b

Please sign in to comment.