Skip to content

Instantly share code, notes, and snippets.

@theY4Kman
Created December 5, 2013 19:38
Show Gist options
  • Select an option

  • Save theY4Kman/7812426 to your computer and use it in GitHub Desktop.

Select an option

Save theY4Kman/7812426 to your computer and use it in GitHub Desktop.
from .fixtures import *
def _keyword_fixture(fn):
fixture_name = fn.__name__
fixture_module = sys.modules[fn.__module__]
@pytest.fixture(autouse=True)
def _autouse_fixture(request):
if fixture_name in request.keywords:
request.getfuncargvalue(fixture_name)
_autouse_fixture.__name__ = '_{}_autouse'.format(fixture_name)
setattr(fixture_module, _autouse_fixture.__name__, _autouse_fixture)
return fn
def keyword_fixture(scope='function', params=None, autouse=False):
if callable(scope) and params is None and autouse is False:
fn = pytest.fixture(scope)
return _keyword_fixture(fn)
else:
def _inner_keyword_fixture(fn):
fn = pytest.fixture(scope, params, autouse)(fn)
return _keyword_fixture(fn)
return _inner_keyword_fixture
@keyword_fixture
def test(request):
pass
import conftest
print dir(conftest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment