Skip to content
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

call pook.off in the end of pook.activate wrapper function #145

Merged
merged 5 commits into from
Oct 15, 2024
Merged
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
1 change: 1 addition & 0 deletions src/pook/activate_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ async def wrapper(*args, **kw):
fn(*args, **kw)
finally:
_engine.disable()
_engine.reset()

return wrapper
1 change: 1 addition & 0 deletions src/pook/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def wrapper(*args, **kw):
fn(*args, **kw)
finally:
_engine.disable()
_engine.reset()

return wrapper

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/api_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import pytest

from pook import api
Expand Down Expand Up @@ -47,3 +48,28 @@ def test_mock_contructors(engine):

assert len(engine.mocks) == 0
assert engine.active is False


def test_activate_as_decorator(engine):
@api.activate
def test_activate():
api.get("foo.com")
assert engine.active is True
assert engine.isdone() is False

test_activate()
assert engine.active is False
assert engine.isdone() is True


async def test_activate_as_decorator_for_async(engine):
@api.activate
async def test_activate():
await asyncio.sleep(0)
api.get("foo.com")
assert engine.active is True
assert engine.isdone() is False

await test_activate()
assert engine.active is False
assert engine.isdone() is True