Is there something like 'autotest' for Python unittests?

后端 未结 11 1427
有刺的猬
有刺的猬 2020-12-23 11:28

Basically, growl notifications (or other callbacks) when tests break or pass. Does anything like this exist?

If not, it should be pretty easy to wri

11条回答
  •  梦毁少年i
    2020-12-23 12:05

    For your third question, maybe the trace module is what you need:

    >>> def y(a): return a*a
    >>> def x(a): return y(a)
    >>> import trace
    >>> tracer = trace.Trace(countfuncs = 1)
    >>> tracer.runfunc(x, 2)
    4
    >>> res = tracer.results()
    >>> res.calledfuncs
    {('', '', 'y'): 1, ('', '', 'x'): 1}
    

    res.calledfuncs contains the functions that were called. If you specify countcallers = 1 when creating the tracer, you can get caller/callee relationships. See the docs of the trace module for more information.

    You can also try to get the calls via static analysis, but this can be dangerous due to the dynamic nature of Python.

提交回复
热议问题