TypeError: unbound method make_request() must be called with XX instance, but how?
- by Dave
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'