CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
792 stars 75 forks source link

Consider creating a decorator that would enable marking bare functions using asserts to be run as a TestCase #13

Closed CleanCut closed 9 years ago

CleanCut commented 10 years ago

Maybe it would be possible to create a decorator which wrapped a bare function and assert and generated a standard unittest class/method out of it. It would require importing the decorator and decorating the function, obviously. Maybe it would look something like this:

from green import testme

@testme
def myfunc():
    assert foo == bar, "foo = bar"

Maybe that could return a wrapped version of the function that would be semantically equivalent to:

import unittest

class TestMyfunc(unittest.TestCase):

    def test_myfunc(self):
        # XXX Call myfunc() and translate its behavior into unittest XXX
CleanCut commented 9 years ago

No, that's more crazy than I want to deal with.