简体   繁体   中英

django_nose ignores wrapped tests

I have such kind of 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

and test:

@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 ignores wrapped tests, and normally runs regular

Django version 2.0.2 django_nose 1.4.5

any ideas?

Using functools.wraps to preserve the name of the wrapped test seems to fix.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM