Is there something like 'autotest' for Python unittests?

后端 未结 11 1380
有刺的猬
有刺的猬 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条回答
  • 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
    {('<stdin>', '<stdin>', 'y'): 1, ('<stdin>', '<stdin>', '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.

    0 讨论(0)
  • 2020-12-23 12:10

    Maybe Nose http://somethingaboutorange.com/mrl/projects/nose/ has a plugin http://somethingaboutorange.com/mrl/projects/nose/doc/writing_plugins.html

    Found this: http://jeffwinkler.net/2006/04/27/keeping-your-nose-green/

    0 讨论(0)
  • 2020-12-23 12:12

    I found autonose to be pretty unreliable but sniffer seems to work very well.

    $ pip install sniffer
    $ cd myproject
    

    Then instead of running "nosetests", you run:

    $ sniffer
    

    Or instead of nosetests --verbose --with-doctest, you run:

    $ sniffer -x--verbose -x--with-doctest
    

    As described in the readme, it's a good idea to install one of the platform-specific filesystem-watching libraries, pyinotify, pywin32 or MacFSEvents (all installable via pip etc)

    0 讨论(0)
  • 2020-12-23 12:13

    One very useful tool that can make your life easier is entr. Written in C, and uses kqueue or inotify under the hood.

    Following command runs your test suite if any *.py file in your project is changed.

    ls */**.py | entr python -m unittest discover -s test
    

    Works for BSD, Mac OS, and Linux. You can get entr from Homebrew.

    0 讨论(0)
  • 2020-12-23 12:16

    You can use nodemon for the task, by watching .py files and execute manage.py test. The command will be: nodemon --ext py --exec "python manage.py test".

    nodemon is an npm package however, I assume you have node installed.

    0 讨论(0)
提交回复
热议问题