Testid: add a test id to each test name output

This plugin adds a test id (like #1) to each test name output. After you’ve run once to generate test ids, you can re-run individual tests by activating the plugin and passing the ids (with or without the # prefix) instead of test names.

For example, if your normal test run looks like:

% nosetests -v
tests.test_a ... ok
tests.test_b ... ok
tests.test_c ... ok

When adding --with-id you’ll see:

% nosetests -v --with-id
#1 tests.test_a ... ok
#2 tests.test_b ... ok
#2 tests.test_c ... ok

Then you can re-run individual tests by supplying just an id number:

% nosetests -v --with-id 2
#2 tests.test_b ... ok

You can also pass multiple id numbers:

% nosetests -v --with-id 2 3
#2 tests.test_b ... ok
#3 tests.test_c ... ok

Since most shells consider ‘#’ a special character, you can leave it out when specifying a test id.

Note that when run without the -v switch, no special output is displayed, but the ids file is still written.

Looping over failed tests

This plugin also adds a mode that will direct the test runner to record failed tests. Subsequent test runs will then run only the tests that failed last time. Activate this mode with the --failed switch:

% nosetests -v --failed
#1 test.test_a ... ok
#2 test.test_b ... ERROR
#3 test.test_c ... FAILED
#4 test.test_d ... ok

On the second run, only tests #2 and #3 will run:

% nosetests -v --failed
#2 test.test_b ... ERROR
#3 test.test_c ... FAILED

As you correct errors and tests pass, they’ll drop out of subsequent runs.

First:

% nosetests -v --failed
#2 test.test_b ... ok
#3 test.test_c ... FAILED

Second:

% nosetests -v --failed
#3 test.test_c ... FAILED

When all tests pass, the full set will run on the next invocation.

First:

% nosetests -v --failed
#3 test.test_c ... ok

Second:

% nosetests -v --failed
#1 test.test_a ... ok
#2 test.test_b ... ok
#3 test.test_c ... ok
#4 test.test_d ... ok

Note

If you expect to use --failed regularly, it’s a good idea to always run run using the --with-id option. This will ensure that an id file is always created, allowing you to add --failed to the command line as soon as you have failing tests. Otherwise, your first run using --failed will (perhaps surprisingly) run all tests, because there won’t be an id file containing the record of failed tests from your previous run.

Options

--with-id

Enable plugin TestId: Activate to add a test id (like #1) to each test name output. Activate with –failed to rerun failing tests only. [NOSE_WITH_ID]

--id-file=FILE

Store test ids found in test runs in this file. Default is the file .noseids in the working directory.

--failed

Run the tests that failed in the last test run.

Plugin

class nose.plugins.testid.TestId

Bases: nose.plugins.base.Plugin

Activate to add a test id (like #1) to each test name output. Activate with –failed to rerun failing tests only.

configure(options, conf)

Configure plugin.

finalize(result)

Save new ids file, if needed.

loadTestsFromNames(names, module=None)

Translate ids in the list of requested names into their test addresses, if they are found in my dict of tests.

options(parser, env)

Register commandline options.

setOutputStream(stream)

Get handle on output stream so the plugin can print id #s

startTest(test)

Maybe output an id # before the test name.

Example output:

#1 test.test ... ok
#2 test.test_two ... ok

Source

Table Of Contents

Previous topic

Skip: mark tests as skipped

Next topic

Xunit: output test results in xunit format

This Page