Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like 'autotest' for Python unittests?

Tags:

python

testing

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

If not, it should be pretty easy to write.. Easiest way would be to..

  1. run python-autotest myfile1.py myfile2.py etc.py
    • Check if files-to-be-monitored have been modified (possibly just if they've been saved).
    • Run any tests in those files.
    • If a test fails, but in the previous run it passed, generate a growl alert. Same with tests that fail then pass.
    • Wait, and repeat steps 2-5.

The problem I can see there is if the tests are in a different file. The simple solution would be to run all the tests after each save.. but with slower tests, this might take longer than the time between saves, and/or could use a lot of CPU power etc..

The best way to do it would be to actually see what bits of code have changed, if function abc() has changed, only run tests that interact with this.. While this would be great, I think it'd be extremely complex to implement?

To summarise:

  • Is there anything like the Ruby tool autotest (part of the ZenTest package), but for Python code?
  • How do you check which functions have changed between two revisions of a script?
  • Is it possible to determine which functions a command will call? (Somewhat like a reverse traceback)
like image 825
dbr Avatar asked Sep 20 '08 18:09

dbr


People also ask

Is there unit testing in Python?

unittest has been built into the Python standard library since version 2.1. You'll probably see it in commercial Python applications and open-source projects. unittest contains both a testing framework and a test runner. unittest has some important requirements for writing and executing tests.


4 Answers

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)

like image 53
jkp Avatar answered Oct 12 '22 18:10

jkp


autonose created by gfxmonk:

Autonose is an autotest-like tool for python, using the excellent nosetest library.

autotest tracks filesystem changes and automatically re-run any changed tests or dependencies whenever a file is added, removed or updated. A file counts as changed if it has iself been modified, or if any file it imports has changed.

...

Autonose currently has a native GUI for OSX and GTK. If neither of those are available to you, you can instead run the console version (with the --console option).

like image 22
dbr Avatar answered Oct 12 '22 19:10

dbr


I just found this: http://www.metareal.org/p/modipyd/

I'm currently using thumb.py, but as my current project transitions from a small project to a medium sized one, I've been looking for something that can do a bit more thorough dependency analysis, and with a few tweaks, I got modipyd up and running pretty quickly.

like image 3
mattorb Avatar answered Oct 12 '22 18:10

mattorb


Guard is an excellent tool that monitors for file changes and triggers tasks automatically. It's written in Ruby, but it can be used as a standalone tool for any task like this. There's a guard-nosetests plugin to run Python tests via nose.

Guard supports cross-platform notifications (Linux, OSX, Windows), including Growl, as well as many other great features. One of my can't-live-without dev tools.

like image 3
Jim Stewart Avatar answered Oct 12 '22 17:10

Jim Stewart