diff --git a/examples/pytest_example.py b/examples/pytest_example.py index 7c08cba..873bb4b 100644 --- a/examples/pytest_example.py +++ b/examples/pytest_example.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index ae086b8..fb858f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/pook/pytest_fixture.py b/src/pook/pytest_fixture.py new file mode 100644 index 0000000..7471fc2 --- /dev/null +++ b/src/pook/pytest_fixture.py @@ -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()