Skip to content

Commit a0863a3

Browse files
authored
Merge pull request #4 from dimagi/dm/pytest-8.4
Fixes for pytest 8.4
2 parents de6c602 + 27a8b1f commit a0863a3

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
python: ['3.9', '3.10', '3.11', '3.12', '3.13']
16+
pytest: ['8.1', '8.2', '8.3', '8.4']
1617
steps:
1718
- uses: actions/checkout@v4
1819
- uses: actions/setup-python@v5
@@ -22,6 +23,7 @@ jobs:
2223
run: |
2324
python --version
2425
pip install --upgrade pip flake8
26+
pip install pytest~=${{ matrix.pytest }}.0
2527
pip install -e .
2628
- name: Run tests
2729
run: pytest

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 1.0.1 - 2025-07-22
2+
3+
- Add support for pytest 8.4
4+
5+
# 1.0.0 - 2024-10-22
6+
7+
- Initial version.

src/unmagic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .fixtures import fixture, use
88
from .scope import get_request
99

10-
__version__ = "1.0.0"
10+
__version__ = "1.0.1"
1111
__all__ = ["autouse", "fixture", "get_request", "use"]
1212

1313
pytest_plugins = ["unmagic.fence", "unmagic.fixtures", "unmagic.scope"]

src/unmagic/_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# flake8: noqa: F401
22
from _pytest.compat import (
33
get_real_func,
4-
is_generator,
54
safe_getattr,
65
safe_isclass,
7-
_PytestWrapper as Wrapper,
86
)
97
from _pytest.fixtures import (
108
_get_direct_parametrize_args as get_direct_parametrize_args,

src/unmagic/autouse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import warnings
2+
from inspect import isgeneratorfunction
23
from pathlib import Path
34

45
from . import _api
@@ -52,7 +53,7 @@ def _register_autouse(fixture, where, session):
5253
if path.name == "__init__.py":
5354
path = path.parent
5455
nodeid = _api.bestrelpath(session.config.invocation_params.dir, path)
55-
assert _api.is_generator(fixture.func), repr(fixture)
56+
assert isgeneratorfunction(fixture.func), repr(fixture)
5657
_api.register_fixture(
5758
session,
5859
name=f"{nodeid}::{fixture._id}",

src/unmagic/fixtures.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
from contextlib import _GeneratorContextManager
99
from functools import cached_property, wraps
10+
from inspect import isgeneratorfunction, Signature
1011
from os.path import dirname
1112
from unittest import mock
1213

@@ -38,7 +39,7 @@ def fixture(func=None, /, scope="function", autouse=False):
3839
a lower scope to retrieve the value of the fixture.
3940
"""
4041
def fixture(func):
41-
if not _api.is_generator(func):
42+
if not isgeneratorfunction(func):
4243
return UnmagicFixture.create(func, scope, autouse)
4344
return UnmagicFixture(func, scope, autouse)
4445
return fixture if func is None else fixture(func)
@@ -78,7 +79,7 @@ def setup_fixtures():
7879
)
7980
func, scope = func.func, func.scope
8081

81-
if _api.is_generator(func):
82+
if isgeneratorfunction(func):
8283
@wraps(func)
8384
def run_with_fixtures(*args, **kw):
8485
setup_fixtures()
@@ -141,11 +142,10 @@ def create(cls, fixture, scope="function", autouse=False):
141142
def func():
142143
with fixture as value:
143144
yield value
144-
func.__pytest_wrapped__ = _api.Wrapper(wrapped)
145145
func.__unmagic_wrapped__ = outer
146-
# delete __wrapped__ to prevent pytest from
147-
# introspecting arguments from wrapped function
148-
del func.__wrapped__
146+
func.__wrapped__ = wrapped
147+
# prevent pytest from introspecting arguments from wrapped function
148+
func.__signature__ = Signature()
149149
return cls(func, scope, autouse)
150150

151151
def __init__(self, func, scope, autouse):
@@ -163,11 +163,6 @@ def _id(self):
163163
def unmagic_fixtures(self):
164164
return self.func.unmagic_fixtures
165165

166-
@property
167-
def __pytest_wrapped__(self):
168-
wrapped = getattr(self.func, "__pytest_wrapped__", None)
169-
return _api.Wrapper(self.func) if wrapped is None else wrapped
170-
171166
@property
172167
def __name__(self):
173168
return self.func.__name__
@@ -202,7 +197,7 @@ def _register(self, node):
202197
scope_node_id = ""
203198
else:
204199
scope_node_id = _SCOPE_NODE_ID[self.scope](node.nodeid)
205-
assert _api.is_generator(self.func), repr(self)
200+
assert isgeneratorfunction(self.func), repr(self)
206201
_api.register_fixture(
207202
node.session,
208203
name=self._id,

tests/test_fixtures.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from contextlib import contextmanager
2+
from inspect import isgeneratorfunction
23
from unittest.mock import patch
34

45
import pytest
56

6-
from unmagic import _api, fence, fixture, get_request, use
7+
from unmagic import fence, fixture, get_request, use
78

89
from .util import get_source, unmagic_tester
910

@@ -57,7 +58,7 @@ def test_use_generator_should_return_generator():
5758
@fix
5859
def gen():
5960
yield
60-
assert _api.is_generator(gen)
61+
assert isgeneratorfunction(gen)
6162

6263

6364
class Thing:

0 commit comments

Comments
 (0)