Skip to content
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
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
fail-fast: false
matrix:
python: ['3.9', '3.10', '3.11', '3.12', '3.13']
pytest: ['8.1', '8.2', '8.3', '8.4']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -22,6 +23,7 @@ jobs:
run: |
python --version
pip install --upgrade pip flake8
pip install pytest~=${{ matrix.pytest }}.0
pip install -e .
- name: Run tests
run: pytest
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 1.0.1 - 2025-07-22

- Add support for pytest 8.4

# 1.0.0 - 2024-10-22

- Initial version.
2 changes: 1 addition & 1 deletion src/unmagic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .fixtures import fixture, use
from .scope import get_request

__version__ = "1.0.0"
__version__ = "1.0.1"
__all__ = ["autouse", "fixture", "get_request", "use"]

pytest_plugins = ["unmagic.fence", "unmagic.fixtures", "unmagic.scope"]
2 changes: 0 additions & 2 deletions src/unmagic/_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# flake8: noqa: F401
from _pytest.compat import (
get_real_func,
is_generator,
safe_getattr,
safe_isclass,
_PytestWrapper as Wrapper,
)
from _pytest.fixtures import (
_get_direct_parametrize_args as get_direct_parametrize_args,
Expand Down
3 changes: 2 additions & 1 deletion src/unmagic/autouse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import warnings
from inspect import isgeneratorfunction
from pathlib import Path

from . import _api
Expand Down Expand Up @@ -52,7 +53,7 @@ def _register_autouse(fixture, where, session):
if path.name == "__init__.py":
path = path.parent
nodeid = _api.bestrelpath(session.config.invocation_params.dir, path)
assert _api.is_generator(fixture.func), repr(fixture)
assert isgeneratorfunction(fixture.func), repr(fixture)
_api.register_fixture(
session,
name=f"{nodeid}::{fixture._id}",
Expand Down
19 changes: 7 additions & 12 deletions src/unmagic/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from contextlib import _GeneratorContextManager
from functools import cached_property, wraps
from inspect import isgeneratorfunction, Signature
from os.path import dirname
from unittest import mock

Expand Down Expand Up @@ -38,7 +39,7 @@ def fixture(func=None, /, scope="function", autouse=False):
a lower scope to retrieve the value of the fixture.
"""
def fixture(func):
if not _api.is_generator(func):
if not isgeneratorfunction(func):
return UnmagicFixture.create(func, scope, autouse)
return UnmagicFixture(func, scope, autouse)
return fixture if func is None else fixture(func)
Expand Down Expand Up @@ -78,7 +79,7 @@ def setup_fixtures():
)
func, scope = func.func, func.scope

if _api.is_generator(func):
if isgeneratorfunction(func):
@wraps(func)
def run_with_fixtures(*args, **kw):
setup_fixtures()
Expand Down Expand Up @@ -141,11 +142,10 @@ def create(cls, fixture, scope="function", autouse=False):
def func():
with fixture as value:
yield value
func.__pytest_wrapped__ = _api.Wrapper(wrapped)
func.__unmagic_wrapped__ = outer
# delete __wrapped__ to prevent pytest from
# introspecting arguments from wrapped function
del func.__wrapped__
func.__wrapped__ = wrapped
# prevent pytest from introspecting arguments from wrapped function
func.__signature__ = Signature()
return cls(func, scope, autouse)

def __init__(self, func, scope, autouse):
Expand All @@ -163,11 +163,6 @@ def _id(self):
def unmagic_fixtures(self):
return self.func.unmagic_fixtures

@property
def __pytest_wrapped__(self):
wrapped = getattr(self.func, "__pytest_wrapped__", None)
return _api.Wrapper(self.func) if wrapped is None else wrapped

@property
def __name__(self):
return self.func.__name__
Expand Down Expand Up @@ -202,7 +197,7 @@ def _register(self, node):
scope_node_id = ""
else:
scope_node_id = _SCOPE_NODE_ID[self.scope](node.nodeid)
assert _api.is_generator(self.func), repr(self)
assert isgeneratorfunction(self.func), repr(self)
_api.register_fixture(
node.session,
name=self._id,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from contextlib import contextmanager
from inspect import isgeneratorfunction
from unittest.mock import patch

import pytest

from unmagic import _api, fence, fixture, get_request, use
from unmagic import fence, fixture, get_request, use

from .util import get_source, unmagic_tester

Expand Down Expand Up @@ -57,7 +58,7 @@ def test_use_generator_should_return_generator():
@fix
def gen():
yield
assert _api.is_generator(gen)
assert isgeneratorfunction(gen)


class Thing:
Expand Down