Metadata-Version: 1.0
Name: pytest-contextfixture
Version: 0.1.1
Summary: Define pytest fixtures as context managers.
Home-page: http://github.com/pelme/pytest-contextfixture/
Author: Andreas Pelme
Author-email: andreas@pelme.se
License: UNKNOWN
Description: pytest-contextfixture makes it possible to define pytest fixtures as context managers.
        
        A contextfixture works like a standard fixture, but it allows the
        definition to be written as a generator. This simplifies the teardown
        code and allows for other context managers to be used within a fixture.
        
        Installation
        ============
        
        pip install pytest-contextfixture
        
        
        
        Usage
        =====
        
        Consider this example, using the standard `pytest.fixture`::
        
            import pytest
        
            @pytest.fixture
            def dependency(request)
                def teardown():
                    # fixture teardown code goes here
                request.addfinalizer(teardown)
        
                return 1234
        
            def test_foo(dependency):
                assert fn_under_test(dependency) == 'expected'
        
        
        With `pytest.contextfixture`, this is equivalent::
        
            import pytest
        
            @pytest.contextfixture
            def dependency(request):
                # fixture setup code goes here
                yield 1234
                # fixture teardown code goes here
        
            def test_foo(dependency):
                assert fn_under_test(dependency) == 'expected'
        
        
        While this is a slightly nicer syntax, when using other context managers
        to get a dependency for a fixture, this becomes more useful::
        
            @pytest_contextfixture
            def dependency(request):
                with setup_something():
                    with setup_something_else() as d:
                        yield d
        
            def test_foo(dependency):
                assert fn_under_test(dependency) == 'expected'
        
        test_foo will then run in the context of setup_something and
        setup_something_else.
        
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Testing
