# -*- coding: utf-8 -*- import pytest from resources import resources resources.register_mod(__name__) @resources.register_func def user(name='John Doe'): """ register function user as a resource. The returned (yielded) value will be used as a resource, function name will be converted to a resource name """ yield {'name': name} @resources.register_func def todo_item(text='Do something'): """ Test of dependent resource which can be added only if user resource does exist. """ yield {'user': resources.user, 'text': text} def test_context_manager(): assert not hasattr(resources, 'user') with resources.user_ctx(): assert resources.user == {'name': 'John Doe'}
def test_import_vs_register(): assert not hasattr(resources, 'foo_ctx') resources.register_mod(__name__) assert hasattr(resources, 'foo_ctx') resources.unregister_mod(__name__) assert not hasattr(resources, 'foo_ctx')
# -*- coding: utf-8 -*- import pytest from resources import resources resources.register_mod(__name__) @resources.register_func def user(name='John Doe'): """ register function user as a resource. The returned (yielded) value will be used as a resource, function name will be converted to a resource name """ yield {'name': name} @resources.register_func def todo_item(text='Do something'): """ Test of dependent resource which can be added only if user resource does exist. """ yield {'user': resources.user, 'text': text} def test_context_manager(): assert not hasattr(resources, 'user') with resources.user_ctx():