pythondjangodjango-nose

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?


Solution

  • 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