Skip to content

Commit 9b2bc8c

Browse files
author
goodboy
authored
Merge pull request #54 from pytest-dev/benchmarking
Baseline benchmarking tests
2 parents 26ddfe4 + 4a8bf5c commit 9b2bc8c

File tree

3 files changed

+74
-13
lines changed

3 files changed

+74
-13
lines changed

.travis.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
sudo: false
22
language: python
33
python:
4-
54
- '2.6'
65
- '2.7'
76
- '3.3'
87
- '3.4'
98
- '3.5'
10-
- '3.6-dev'
9+
- '3.6'
1110
- pypy
1211
- nightly
12+
1313
# command to install dependencies
1414
install: "pip install -U tox"
15-
# # command to run tests
15+
16+
# command to run tests
1617
env:
1718
matrix:
1819
- TOXENV=py-pytest28
1920
- TOXENV=py-pytest29
2021
- TOXENV=py-pytest30
22+
2123
matrix:
2224
include:
2325
- python: '2.7'
2426
env: TOXENV=check
25-
- python: '3.5'
27+
- python: '3.6'
2628
env: TOXENV=check
29+
- python: '2.7'
30+
env: TOXENV=benchmark
31+
- python: '3.6'
32+
env: TOXENV=benchmark
33+
2734
script:
2835
- tox --recreate -e $TOXENV
2936

testing/benchmark.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Benchmarking and performance tests.
3+
"""
4+
import pytest
5+
from pluggy import _MultiCall, HookImpl, HookspecMarker, HookimplMarker
6+
7+
hookspec = HookspecMarker("example")
8+
hookimpl = HookimplMarker("example")
9+
10+
11+
def MC(methods, kwargs, firstresult=False):
12+
hookfuncs = []
13+
for method in methods:
14+
f = HookImpl(None, "<temp>", method, method.example_impl)
15+
hookfuncs.append(f)
16+
return _MultiCall(hookfuncs, kwargs, {"firstresult": firstresult})
17+
18+
19+
@hookimpl
20+
def hook(arg1, arg2, arg3):
21+
return arg1, arg2, arg3
22+
23+
24+
@hookimpl(hookwrapper=True)
25+
def wrapper(arg1, arg2, arg3):
26+
yield
27+
28+
29+
@pytest.fixture(
30+
params=[0, 1, 10, 100],
31+
ids="hooks={}".format,
32+
)
33+
def hooks(request):
34+
return [hook for i in range(request.param)]
35+
36+
37+
@pytest.fixture(
38+
params=[0, 1, 10, 100],
39+
ids="wrappers={}".format,
40+
)
41+
def wrappers(request):
42+
return [wrapper for i in range(request.param)]
43+
44+
45+
def inner_exec(methods):
46+
return MC(methods, {'arg1': 1, 'arg2': 2, 'arg3': 3}).execute()
47+
48+
49+
def test_hook_and_wrappers_speed(benchmark, hooks, wrappers):
50+
benchmark(inner_exec, hooks + wrappers)

tox.ini

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
[tox]
2-
envlist=check,py{26,27,34,35,py}-pytest{28,29,30}
2+
envlist=check,py{26,27,34,35,36,py}-pytest{28,29,30}
33

44
[testenv]
5-
commands= py.test {posargs:testing/}
5+
commands=py.test {posargs:testing/}
66
deps=
77
pytest28: pytest~=2.8.0
88
pytest29: pytest~=2.9.0
99
pytest30: pytest~=3.0.0
1010

11+
[testenv:benchmark]
12+
commands=py.test {posargs:testing/benchmark.py}
13+
deps=
14+
pytest
15+
pytest-benchmark
1116

1217
[testenv:check]
1318
deps =
1419
flake8
15-
restructuredtext_lint
16-
commands =
20+
restructuredtext_lint
21+
commands =
1722
flake8 pluggy.py setup.py testing
1823
rst-lint CHANGELOG.rst README.rst
1924

20-
2125
[testenv:docs]
2226
deps =
2327
sphinx
2428
pygments
25-
2629
commands =
2730
sphinx-build \
2831
-b html \
2932
{toxinidir}/docs {toxinidir}/build/html-docs
33+
3034
[pytest]
3135
minversion=2.0
3236
#--pyargs --doctest-modules --ignore=.tox
33-
addopts= -rxsX
34-
norecursedirs = .tox ja .hg .env*
37+
addopts=-rxsX
38+
norecursedirs=.tox ja .hg .env*
3539

3640
[flake8]
37-
max-line-length = 99
41+
max-line-length=99

0 commit comments

Comments
 (0)