【发布时间】:2013-11-15 22:50:10
【问题描述】:
我跑
nosetests -v --nocapture --nologcapture tests/reward/test_stuff.py
我明白了
----------------------------------------------------------------------
Ran 7 tests in 0.005s
OK
没有装饰器的测试运行良好,但是我有一些固定测试设置,因此没有在上述命令中运行:
@use_fixtures(fixtures.ap_user_data, fixtures.ap_like_data, fixtures.other_reward_data)
def test_settings_are_respected(data):
"""
Tests setting takes effect
"""
res = func()
assert len(res) > 0
装饰器是:
def use_fixtures(*fixtures):
"""
Decorator for tests, abstracts the build-up required when using fixtures
"""
def real_use_fixtures(func):
def use_fixtures_inner(*args, **kwargs):
env = {}
for cls in fixtures:
name = cls.__name__
table = name[:-5] #curtails _data
env[table] = get_orm_class(table)
fixture = SQLAlchemyFixture(env=env, engine=engine, style=TrimmedNameStyle(suffix="_data"))
return fixture.with_data(*fixtures)(func)()
return use_fixtures_inner
return real_use_fixtures
我使用装饰器会阻止鼻子测试运行我的测试吗?
【问题讨论】:
标签: python sqlalchemy decorator fixtures