Skip to content

Instantly share code, notes, and snippets.

@hpk42
Created September 26, 2013 12:38
Show Gist options
  • Save hpk42/6713581 to your computer and use it in GitHub Desktop.
Save hpk42/6713581 to your computer and use it in GitHub Desktop.
import pytest
import contextlib
@contextlib.contextmanager
def ctx():
print "setup ctx"
yield 1
print "teardown ctx"
@pytest.fixture
def fix(request):
with request.wrap_contextmanager(ctx()) as x:
return x
def test_fix(fix):
print "test called"
@hpk42
Copy link
Author

hpk42 commented Sep 26, 2013

it prints:

setup ctx
test called
teardown ctx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment