django_nose忽略包装测试

时间:2018-03-29 11:58:51

标签: python django django-nose

我有这种包装

def external_services_mock(f):
    @patch('service.remote_call1')
    @patch('service.remote_call2')
    def wrapper(self, remote_call2_mock, remote_call1_mock, *args, **kwargs):
        remote_call1_mock.return_value = None

        def test_mocks():
            return remote_call1_mock, remote_call2_mock

        f(self, test_mocks, *args, **kwargs)

    return wrapper

并测试:

@external_services_mock
def test_add_callback(self, test_mocks):
    remote_call1_mock, remote_call2_mock = test_mocks()

    // do smth

    // assert smth

django_nose runner忽略包装测试,通常会定期运行

Django 2.0.2版 django_nose 1.4.5

任何想法?

1 个答案:

答案 0 :(得分:0)

使用functools.wraps保留包装测试的名称似乎已修复。

from functools import wraps

def external_services_mock(f):
    @patch('service.remote_call1')
    @patch('service.remote_call2')
    @wraps(f)
    def wrapper(self, remote_call2_mock, remote_call1_mock, *args, **kwargs):
        remote_call1_mock.return_value = None

        def test_mocks():
            return remote_call1_mock, remote_call2_mock

        f(self, test_mocks, *args, **kwargs)

    return wrapper