Skip to content

Commit

Permalink
Fix bad fixture check. Close #271.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Oct 30, 2024
1 parent 614df44 commit 6318314
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ addopts =
--ignore=src/pytest_benchmark/pep418.py
--doctest-modules
--doctest-glob=\*.rst
--nbmake
--tb=short
testpaths =
tests
Expand Down
6 changes: 4 additions & 2 deletions src/pytest_benchmark/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,12 @@ def pytest_runtest_setup(item):
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
fixture = hasattr(item, 'funcargs') and item.funcargs.get('benchmark')
fixture = None
if hasattr(item, 'funcargs'):
fixture = item.funcargs.get('benchmark')
if fixture is not None and not isinstance(fixture, BenchmarkFixture):
raise TypeError(
f'unexpected type for `benchmark` in funcargs, {fixture!r} must be a BenchmarkFixture instance.'
f'unexpected type for `benchmark` in funcargs, {fixture!r} must be a BenchmarkFixture instance. '
'You should not use other plugins that define a `benchmark` fixture, or return and unexpected value if you do redefine it.'
)
if fixture:
Expand Down
50 changes: 50 additions & 0 deletions tests/test_nbmake.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"cells": [
{
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-10-30T00:19:36.564972Z",
"start_time": "2024-10-30T00:19:36.560019Z"
}
},
"source": [
"a = 1\n",
"print(a)"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n"
]
}
],
"execution_count": 1
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
11 changes: 6 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ usedevelop =
cover: true
nocov: false
deps =
pytest-instafail==0.4.2
xdist: pytest-xdist==2.5.0
pytest-instafail==0.5.0
xdist: pytest-xdist==3.6.1
pytest71: pytest==7.1.3
pytest72: pytest==7.2.2
pytest73: pytest==7.3.2
Expand All @@ -54,12 +54,13 @@ deps =
cover: coverage
pypy: jitviewer
aspectlib==2.0.0
pygal==3.0.4
pygal==3.0.5
pygaljs==1.0.2
freezegun==1.3.1
freezegun==1.5.1
hunter
setuptools
elasticsearch==8.11.1
elasticsearch==8.15.1
nbmake==1.5.4
commands =
nocov: {posargs:pytest -vv --ignore=src}
cover: {posargs:pytest --cov --cov-report=term-missing --cov-report=xml -vv}
Expand Down

0 comments on commit 6318314

Please sign in to comment.