Skip to content

Commit

Permalink
Add a pytest fixture for pook
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn committed Jun 29, 2024
1 parent df93cbb commit db562b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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
11 changes: 11 additions & 0 deletions src/pook/pytest_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

import pook as pook_mod


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

0 comments on commit db562b2

Please sign in to comment.