import functools
from scipy import integrate

def counted_calls(f):
    @functools.wraps(f)
    def count_wrapper(*args, **kwargs):
        count_wrapper.count += 1
        return f(*args, **kwargs)
    count_wrapper.count = 0
    return count_wrapper

def f(x): return x**2

wrapped = counted_calls(f)
integrate.quad(wrapped, 0, 1)
print(wrapped.count)