Call an external function without sending "self" arg

I write tests for a Django application and use the attribute on my test class to save which view it should test, for example:

# IN TESTS.PY
class OrderTests(TestCase, ShopTest):
    _VIEW = views.order

    def test_gateway_answer(self):
        url = 'whatever url'
        request = self.request_factory(url, 'GET')
        self._VIEW(request, **{'sku': order.sku})


# IN VIEWS.PY
def order(request, sku)
    ...

I am assuming that the problem I am having is caused by the fact that since I am calling the class attribute OrderTests, python assumes that I want to send selfand then orderreceive the wrong arguments. It's easy to decide ... just don't use it as an attribute of a class, but I was wondering if there is a way to tell python not to send itself in this case.

Thank.

+5
source share
1 answer

, Python descriptors, , , ( self) .

_VIEW , :

class OrderTests(TestCase, ShopTest):
    _VIEW = views.order

    def test_gateway_answer(self):
        url = 'whatever url'
        request = self.request_factory(url, 'GET')
        OrderTests._VIEW(request, **{'sku': order.sku})

staticmethod, :

class OrderTests(TestCase, ShopTest):
    _VIEW = staticmethod(views.order)

    def test_gateway_answer(self):
        url = 'whatever url'
        request = self.request_factory(url, 'GET')
        self._VIEW(request, **{'sku': order.sku})
+9

All Articles