Skip to content

Commit

Permalink
Add a pytest fixture for pook (#134)
Browse files Browse the repository at this point in the history
* Add a pytest fixture for pook

* use context-manager
  • Loading branch information
wimglenn authored Jul 1, 2024
1 parent df93cbb commit b8fb877
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions History.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Draft v2.0.0 / Unreleased

* These classes never implemented regex matching

* Add a pytest fixture to the package.

v1.4.3 / 2024-02-23
-------------------

Expand Down
6 changes: 6 additions & 0 deletions examples/pytest_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ def test_no_match_exception():
pook.get("server.com/bar", reply=204)
with pytest.raises(Exception):
requests.get("http://server.com/baz")


def test_fixture(pook):
pook.get("https://example.org/").reply(204)
res = requests.get("https://example.org/")
assert res.status_code == 204
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ requires-python = ">=3.8"
[project.urls]
Homepage = "https://github.com/h2non/pook"

[project.entry-points.pytest11]
pook = "pook.pytest_fixture"

[tool.hatch.version]
path = "src/pook/__init__.py"

Expand Down
10 changes: 10 additions & 0 deletions src/pook/pytest_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

import pook as pook_mod


@pytest.fixture
def pook():
"""Pytest fixture for HTTP traffic mocking and testing"""
with pook_mod.use():
yield pook_mod

0 comments on commit b8fb877

Please sign in to comment.