Skip to content

Commit 8dfeeec

Browse files
committed
Fix broken hooks on pytest 8.1+ (and set that as the min supported version). Fixes #263.
1 parent 41302ed commit 8dfeeec

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog
33
=========
44

5+
5.1.0 (2024-10-30)
6+
------------------
7+
8+
* Fixed broken hooks handling on pytest 8.1 or later (the ``TypeError: import_path() missing 1 required keyword-only argument: 'consider_namespace_packages'`` issue).
9+
Unfortunately this sets the minimum supported pytest version to 8.1.
10+
511
5.0.1 (2024-10-30)
612
------------------
713

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def read(*names, **kwargs):
6262
],
6363
python_requires='>=3.9',
6464
install_requires=[
65-
'pytest>=3.8',
65+
'pytest>=8.1',
6666
'py-cpuinfo',
6767
],
6868
extras_require={

src/pytest_benchmark/cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from _pytest import pathlib
55
from _pytest._io import TerminalWriter
6+
from _pytest.config.findpaths import locate_config
67

78
from pytest_benchmark.csv import CSVResults
89

@@ -108,10 +109,16 @@ def make_parser():
108109

109110

110111
class HookDispatch:
111-
def __init__(self, **kwargs):
112+
def __init__(self, *, root, **kwargs):
113+
_, _, config = locate_config(invocation_dir=root, args=())
112114
conftest_file = pathlib.Path('conftest.py')
113115
if conftest_file.exists():
114-
self.conftest = pathlib.import_path(conftest_file, **kwargs)
116+
self.conftest = pathlib.import_path(
117+
conftest_file,
118+
**kwargs,
119+
root=root,
120+
consider_namespace_packages=bool(config.get('consider_namespace_packages')),
121+
)
115122
else:
116123
self.conftest = None
117124

tests/test_cli.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44

55
import pytest
6+
from _pytest.legacypath import Testdir
67
from _pytest.pytester import LineMatcher
78

89
pytest_plugins = ('pytester',)
@@ -143,6 +144,52 @@ def test_help_compare(testdir, args):
143144
assert result.ret == 0
144145

145146

147+
def test_hooks(testdir: Testdir):
148+
testdir.makepyfile(
149+
conftest="""
150+
def pytest_benchmark_scale_unit(config, unit, benchmarks, best, worst, sort):
151+
return '', 1
152+
"""
153+
)
154+
result = testdir.run('py.test-benchmark', '--storage', STORAGE, 'list')
155+
assert result.stderr.lines == []
156+
result.stdout.fnmatch_lines(
157+
[
158+
'*0001_*.json',
159+
'*0002_*.json',
160+
'*0003_*.json',
161+
'*0004_*.json',
162+
'*0005_*.json',
163+
'*0006_*.json',
164+
'*0007_*.json',
165+
'*0008_*.json',
166+
'*0009_*.json',
167+
'*0010_*.json',
168+
'*0011_*.json',
169+
'*0012_*.json',
170+
'*0013_*.json',
171+
'*0014_*.json',
172+
'*0015_*.json',
173+
'*0016_*.json',
174+
'*0017_*.json',
175+
'*0018_*.json',
176+
'*0019_*.json',
177+
'*0020_*.json',
178+
'*0021_*.json',
179+
'*0022_*.json',
180+
'*0023_*.json',
181+
'*0024_*.json',
182+
'*0025_*.json',
183+
'*0026_*.json',
184+
'*0027_*.json',
185+
'*0028_*.json',
186+
'*0029_*.json',
187+
'*0030_*.json',
188+
]
189+
)
190+
assert result.ret == 0
191+
192+
146193
def test_list(testdir):
147194
result = testdir.run('py.test-benchmark', '--storage', STORAGE, 'list')
148195
assert result.stderr.lines == []

0 commit comments

Comments
 (0)