nose-devs/nose — Issue #69: Allow test generators to provide test description
Author: jpellerin
Created: 2011-12-14 15:57:50+00:00
State: closed

Generator expressions are very helpful in testing a range of test cases
based on data rather than manually maintaining a large collection of tests.
For example, testing a search engine by iterating through a set of sample
queries and comparing the results against a gold standard set of correct
search results. Generator expressions let me write one test method that
iterates over these cases and yields to a simple test function that
performs the actual check, giving each test its own identity:

def check_id_in_results(id, searchresults, criteria):
assert id in searchresults, "Search %s did not return expected ID %s" %
(criteria,id)

This will let me run a bunch of search criteria, and generate a unique
version of check_id_in_results for each case to test the results of that
particular search.

A shortcoming of this approach is that test generator automatically names
the generated test based on the yielded tuple. In the above case, if the
search engine returns 100 results this will result in a very long name,
something like:

test_search.test_with_dataset:('11897616', [u'16288100', u'15930030',
u'16247021', u'16188939', u'15967793', u'15894538', ... ], 'my search terms')

This can make logs massive and difficult to manage. It would be nice if the
yield expression could provide a shorter test name or description -- still
unique for each yield expression -- to be used to keep test logs more readable.

For example, instead of a callable as the first member of the yielded
tuple, allow (callable, testdesc), where tesddesc is a string description
to be associated with the generated test.

Google Code Info:
Issue #: 51
Author: felci...@gmail.com
Created On: 2007-04-13T01:17:13.000Z
Closed On: 2007-08-24T13:20:28.000Z