Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for standalone test functions #11

Open
croach opened this issue Mar 22, 2015 · 0 comments
Open

Add support for standalone test functions #11

croach opened this issue Mar 22, 2015 · 0 comments

Comments

@croach
Copy link
Owner

croach commented Mar 22, 2015

The py.test and nose libraries support standalone test functions (the unittest standard library does not). I'd like to add support for these standalone functions to the Flask-Fixtures library.

If we wrap each function with a class that inherits from the FixturesMixin (a simplified example listed below) we'll be able to use standalone functions even when using the unittest library. This may be a good or bad thing since it means that decorated functions will work with unittest, but regular functions without the decorator will not, which may be a bit confusing to anyone writing tests. The alternative is just to wrap the test function in another function and the py.test and nose libraries will work properly, and unittest will continue to not work with any standalone functions.

import unittest
from functools import wraps

def bar(fn):
    @wraps(fn)
    def _test_fn(self):
        print
        print "do something before..."
        fn()
        print "do something after..."

    return type('Test_' + fn.__name__, (unittest.TestCase,), {
        fn.__name__: _test_fn
    })

@bar
def test():
    assert True

@bar
def test2():
    assert True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant