django_nose 忽略包装测试
django_nose ignores wrapped tests
我有这样的包装纸
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_nose1.4.5
有什么想法吗?
使用 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
我有这样的包装纸
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_nose1.4.5
有什么想法吗?
使用 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