File: test_with_weaver.py

package info (click to toggle)
python-pytest-benchmark 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,072 kB
  • sloc: python: 5,232; makefile: 12
file content (29 lines) | stat: -rw-r--r-- 557 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time

import pytest

aspectlib = pytest.importorskip("aspectlib")

class Foo:
    def __init__(self, arg=0.01):
        self.arg = arg

    def run(self):
        self.internal(self.arg)

    def internal(self, duration):
        time.sleep(duration)


@pytest.mark.benchmark(max_time=0.001)
def test_weave_fixture(benchmark_weave):
    benchmark_weave(Foo.internal, lazy=True)
    f = Foo()
    f.run()


@pytest.mark.benchmark(max_time=0.001)
def test_weave_method(benchmark):
    benchmark.weave(Foo.internal, lazy=True)
    f = Foo()
    f.run()