Last Updated: February 25, 2016
·
1.891K
· chrismckinnel

Use nosy to automatically run your python tests on code change

Nosy is a nifty little python package that will run your tests with nose whenever any of your python source files change.

I find it really useful to have nosy visible somewhere so every time I save a file, it'll fire off my tests and I can see if my changes break any other parts of the application right when I make the changes.

Usually you have to wait until you either run the tests yourself or your CI server picks up that something has gone wrong if you don't happen to run your tests before committing (shame on you if this is the case!).

This can cost you some time because you need to remember what it was you changed, where you changed it and why you changed it. Using nosy gives you instant feedback when you make changes, saving you time and running your tests more (always a good thing!).

Here's my nosy config file:

# Sample config file section for nosy

# Including this file in the paths to check allows you to change
# nose's behaviour on the fly.

[nosy]
# Paths to check for changed files; changes cause nose to be run
base_path = ./
glob_patterns = *.py
exclude_patterns = *_flymake.*
extra_paths = nosy.cfg
# Command line options to pass to nose
options = 
# Command line arguments to pass to nose; e.g. part of test suite to run
tests = 

I have nosy.cfg in extra_paths so it'll re-run the tests if I make any changes to the config, too.

I set up a pane in terminator and put it somewhere where it's always visible and run nosy with:

nosy -c nosy.cfg