nose-devs/nose — pull request #600 by bmironenko (2013-01-16 00:11:48+00:00)
Title: Add a way to manually designate a test generator

Sometimes one cannot rely on Python's introspection mechanism to detect test generators. This notably happens when using patch decorators in the mock library. The problem is also described here: http://code.google.com/p/mock/issues/detail?id=172.

The proposed solution is to add a test_generator decorator function which attaches a magic ```__test_generator__``` attribute to its target, and check for it in ```nose.util.isgenerator()```. The issue above can then be resolved like this:

```python
@nose.tools.test_generator
@mock.patch("useless_module.SomeClass")
def test_method(self, mock_someclass):
for i in range(3):
result = i * 3
yield self.check_call, i, result
```

This admittedly less than elegant, but I can't think of anything that would be reliable in this respect.