• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cokelaer / easydev / 23640304403

27 Mar 2026 09:41AM UTC coverage: 94.743% (+0.6%) from 94.132%
23640304403

push

github

cokelaer
add more tests

775 of 818 relevant lines covered (94.74%)

5.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/easydev/profiler.py
1
# -*- python -*-
2
# -*- coding: utf-8 -*-
3
#
4
#  This file is part of the easydev software
5
#
6
#  Copyright (c) 2011-2024
7
#
8
#  File author(s): Thomas Cokelaer <cokelaer@gmail.com>
9
#
10
#  Distributed under the BSD3 License.
11
#
12
#  Website: https://github.com/cokelaer/easydev
13
#  Documentation: http://easydev-python.readthedocs.io
14
#
15
##############################################################################
16
"""
17

18
Usage::
19

20
    from easydev import do_profile
21
    @do_profile()
22
    def test():
23
        x = 1
24
        x *= x
25
        return x
26

27
# source: https://zapier.com/engineering/profiling-python-boss/
28

29

30
Requires line_profiler to be installed. line_profiler has C code and we wish
31
easydev to be as simple as possible. So, we do not want compiled code dependencies.
32
Consequently, we added line_profiler in the extra_requires instead of requires
33
in the setup.py One must install line_profiler itself.
34
"""
35

36
__all__ = ["do_profile"]
6✔
37

38
try:
6✔
39
    from line_profiler import LineProfiler
6✔
40

41
    def do_profile(follow=[]):
6✔
42
        def inner(func):
6✔
43
            def profiled_func(*args, **kwargs):
6✔
44
                try:
6✔
45
                    profiler = LineProfiler()
6✔
46
                    profiler.add_function(func)
6✔
47
                    for f in follow:
6✔
48
                        profiler.add_function(f)
3✔
49
                    profiler.enable_by_count()
6✔
50
                    return func(*args, **kwargs)
3✔
51
                finally:
52
                    profiler.print_stats()
3✔
53

54
            return profiled_func
6✔
55

56
        return inner
6✔
57

58
except ImportError:  # pragma: no cover
59

60
    def do_profile(follow=[]):
61
        "Helpful if you accidentally leave in production!"
62
        print("easydev warning:: line_profiler does not seem to be installed. " + "Type 'pip install line_profiler'")
63

64
        def inner(func):
65
            def nothing(*args, **kwargs):
66
                return func(*args, **kwargs)
67

68
            return nothing
69

70
        return inner
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc