【问题标题】:nosetests not running all the tests in a file鼻子测试没有运行文件中的所有测试
【发布时间】: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


    【解决方案1】:

    我不知道你的装饰器是否导致鼻子错过测试,但如果你用装饰器进行测试,然后移除装饰器足够长的时间以查看它是否仍然错过呢?

    【讨论】:

    • 很好,我删除了装饰器,它通过了测试但失败了,因为预加载器预期的一些数据丢失了。现在我可以肯定地说它是装饰器,但我不确定为什么。
    • 可能是应用了装饰器后,nosetests 对测试名称的看法不同,因此认为它不是测试并忽略它。您可能想尝试使用functools.wraps 编写装饰器,这有助于保留原始函数的文档字符串等属性。
    猜你喜欢
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 2015-08-11
    • 2015-08-21
    • 2012-10-03
    • 1970-01-01
    • 2011-07-31
    相关资源
    最近更新 更多