Skip to main content

No project description provided

Project description

nose-knows is a nose plugin for figuring out which unit tests you should run after modifying code. It works by tracing your code while you run unit tests, and creating an output file that can be used later.


You can install nose-knows through pip or easy-install:

pip install nose-knows

Or you can download the latest development version, which may contain new features.

Using nose-knows

nose-knows can be invoked in either input or output mode. In output mode (--knows-out) it will generate a .knows file that contains the mapping from a file in your code tree to the set of unit tests that run it. In input mode, it uses the .knows file to selectively run unit tests based on the files you pass in. Note: here, $BASE_DIR is the name of the base project directory, not the (direct / relative) path to it. It is used to figure out how to rename the file names in the output file to make it more portable.

Creating a .knows file:

eyal-01575:src eyal$ nosetests --with-knows --knows-dir=$BASE_DIR --knows-out
Ran 62 tests in 0.444s


The .knows file now contains the following:


You can now run nose-knows in input mode, passing in load_data/sql_utils/

eyal-01575:src eyal$ nosetests --with-knows --knows-dir=$BASE_DIR load_data/sql_utils/
Ran 7 tests in 0.003s


There is also (experimental at this point) support for py.test. You can generate your .knows file via:

eyal-01575:src eyal$ py.test --with-knows --knows-dir=$BASE_DIR --knows-out
===================== test session starts ======================
platform darwin -- Python 2.7.1 -- pytest-2.3.4
plugins: nose-knows
collected 62 items

tests/ ....
tests/ ..
tests/ .....
tests/ ........
tests/ .....
tests/ .
tests/ .................
tests/test_transformers/ ..
tests/test_transformers/ ...
tests/test_transformers/ ....
tests/test_transformers/ .....
tests/test_transformers/ ..
tests/test_transformers/ ..
tests/test_transformers/ ..

================== 62 passed in 2.18 seconds ===================

And selectively run specific unit tests like so:

eyal-01575:src eyal$ py.test --with-knows --knows-dir=$BASE_DIR load_data/sql_utils/
===================== test session starts ======================
platform darwin -- Python 2.7.1 -- pytest-2.3.4
plugins: nose-knows
collected 62 items

tests/ ....
tests/ ...

=================== 7 passed in 0.30 seconds ===================

The best practice here is to have a system like Jenkins run the unit test suite once in a while to create this map (we have it running daily), and then creating a bash function/script to download the knows output file from Jenkins and run it against the set of changed files from a commit. Ours looks like:

function grab_latest_knows_output() {
    NOW=`date +%s`
    if [ ! -f $KNOWS_FILE_TMP ] ; then
        curl --compressed $KNOWS_FILE_URL > $KNOWS_FILE_TMP
        KNOWS_FILE_AGE=`stat -c %Y $KNOWS_FILE_TMP`
        if [ `expr $NOW - $KNOWS_FILE_AGE` -gt "86400" ] ; then
            curl --compressed $KNOWS_FILE_URL > $KNOWS_FILE_TMP
            echo "Using latest knows output file."

function test_changed() {
    nosetests $KNOWS_FLAGS `git diff --name-only --cached origin | xargs`

function run_tests_for() {
    nosetests $KNOWS_FLAGS $@


nose-knows is copyright 2013 Eventbrite and Contributors, and is made available under BSD-style license; see LICENSE for details.



Adding support for non-unittest based tests with nose.


Minor bug fix to make the nose plugin more resilient to bad test names.


Release date: April 2nd, 2012

  • Initial write of nose-knows, including support for nose and experimental support for py.test

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nose-knows-0.2.tar.gz (7.0 kB view hashes)

Uploaded source

Built Distribution

nose_knows-0.2-py2.py3-none-any.whl (9.7 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page