File: test_context_manager.py

package info (click to toggle)
python-pyinstrument 5.1.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,624 kB
  • sloc: python: 6,713; ansic: 897; makefile: 46; sh: 26; javascript: 18
file content (36 lines) | stat: -rw-r--r-- 788 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
30
31
32
33
34
35
36
from test.fake_time_util import fake_time

import pytest

import pyinstrument
from pyinstrument.context_manager import ProfileContext


def test_profile_context_decorator(capfd):
    with fake_time() as clock:

        @pyinstrument.profile
        def my_function():
            clock.sleep(1.0)

        my_function()

    out, err = capfd.readouterr()
    print(err)
    assert "Function test_profile_context_decorator" in err
    assert "1.000 my_function" in err


def test_profile_context_manager(capfd):
    with fake_time() as clock:
        with pyinstrument.profile():

            def my_function():
                clock.sleep(1.0)

            my_function()

    out, err = capfd.readouterr()
    print(err)
    assert "Block at" in err
    assert "1.000 my_function" in err