TypeError: unbound method make_request() must be called with XX instance, but how?

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2012-11-17T16:48:18Z Indexed on 2012/11/17 17:00 UTC
Read the original article Hit count: 329

Filed under:

Running the code below I get

E TypeError: unbound method make_request() must be called with A instance as first argument (got str instance instead)

I dont want to set make_request method as static, I want to call it from an instance of an object.

The example http://pytest.org/latest/fixture.html#fixture-function

# content of ./test_smtpsimple.py
import pytest

@pytest.fixture
def smtp():
    import smtplib
    return smtplib.SMTP("merlinux.eu")

def test_ehlo(smtp):
    response, msg = smtp.ehlo()
    assert response == 250
    assert "merlinux" in msg
    assert 0 # for demo purposes

My code

""" """
import pytest


class  A(object):
    """  """
    def __init__(self, name ):
        """ """
        self._prop1 = [name]


    @property
    def prop1(self):
        return self._prop1  

    @prop1.setter
    def prop1(self, arguments):
        self._prop1 = arguments

    def make_request(self, sex):
        return 'result'

    def __call__(self):
        return self


@pytest.fixture()
def myfixture():
    """ """
    A('BigDave')
    return A

def test_validateA(myfixture):
    result = myfixture.make_request('male')
    assert result =='result'

© Stack Overflow or respective owner

Related posts about python