Search code examples
pythonnosenose-parameterized

Print name of test function in nose_parametrized


I have test classes that extend unittest.TestCase, and use nose_parameterized for parameterization. I'm using nosetests -v to run the tests. I have nosetests version 1.3.7.

I'd like the test runner to print the name of each test. Instead it just prints the parameters passed into the test.

Here's an example of my actual output:

[with sentence='Put it on the top shelf of the bookshelf'] ... ok
[with **None={'world': [<WorldObject table>, ...'basic', 'language': 'Pick cup'}] ... ERROR
[with **None={'name': 'first action', 'langua...'' ... ERROR
[with **None={'name': 'two pointing choices',...'' ... ERROR

Based on examples from the documentation for nose_parameterized, I think the output should incorporate the name of my test method and its class, approximately like this.

language_analyzer_test (md.LangaugeAnalyzerTest) ... ok
language_test (md.ReferenceResolverTest) ... ERROR
reference_resolver_test (md.ReferenceResolverTest) ... ERROR
reference_resolver_test (md.ReferenceResolverTest) ... ERROR

But it doesn't.

The documentation further states:

If the first parameter is a string, that string will be added to the end of the method name.

So based on the strings I'm passing in as the first parameter to each tests, the output should look like this:

language_analyzer_test_Pick_cup (md.LangaugeAnalyzerTest) ... ok
language_test_basic (md.ReferenceResolverTest) ... ERROR
reference_resolver_test_first_action (md.ReferenceResolverTest) ... ERROR
reference_resolver_test_two_pointing_choices (md.ReferenceResolverTest) ... ERROR

But alas.

Based on the actual output, it's hard to tell which test method is being run or even which test class it's from.

How can I get nose to print the test name for each test case?


Solution

  • If the method under test has a docstring, nose-parameterized will add the parameters (the [with …], above) to the docstring, and nose will print the docstring along with each test.

    If you remove the docstring from the tests, you should get the method name as shown in the documentation.