Skip to content

feat: Register httpx_auth.testing as pytest plugin #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,10 @@ Testing the code using `httpx_auth` authentication classes can be achieved using
### token_cache_mock

```python
from httpx_auth.testing import token_cache_mock, token_mock
import pytest

def test_something(token_cache_mock):
@pytest.mark.usefixture("token_cache_mock")
def test_something():
# perform code using authentication
pass
```
Expand Down Expand Up @@ -933,15 +934,14 @@ You can however return your custom token by providing your own `token_mock` fixt
```python
import pytest

from httpx_auth.testing import token_cache_mock


@pytest.fixture
def token_mock() -> str:
return "MyCustomTokenValue"


def test_something(token_cache_mock):
@pytest.mark.usefixtures("token_cache_mock")
def test_something():
# perform code using authentication
pass
```
Expand All @@ -952,7 +952,8 @@ Note that [`pyjwt`](https://pypi.org/project/PyJWT/) is a required dependency in

```python
import pytest
from httpx_auth.testing import token_cache_mock, create_token

from httpx_auth.testing import create_token


@pytest.fixture
Expand All @@ -961,7 +962,8 @@ def token_mock() -> str:
return create_token(expiry)


def test_something(token_cache_mock):
@pytest.mark.usefixtures("token_cache_mock")
def test_something():
# perform code using authentication
pass
```
Expand All @@ -973,9 +975,10 @@ def test_something(token_cache_mock):
This [`pytest`][6] fixture will return the token cache and ensure it is reset at the end of the test case.

```python
from httpx_auth.testing import token_cache
import pytest

def test_something(token_cache):
@pytest.mark.usefixture("token_cache")
def test_something():
# perform code using authentication
pass
```
Expand All @@ -991,7 +994,7 @@ With this [`pytest`][6] fixture you will be allowed to fine tune your authentica
```python
import datetime

from httpx_auth.testing import browser_mock, BrowserMock, create_token
from httpx_auth.testing import BrowserMock, create_token

def test_something(browser_mock: BrowserMock):
token_expiry = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=1)
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ testing = [
"pytest-asyncio==0.25.*",
]

[project.entry-points.pytest11]
httpx_auth = "httpx_auth.testing"

[tool.setuptools.dynamic]
version = {attr = "httpx_auth.version.__version__"}

Expand Down