運行下面的代碼,我得到TypeError:unbound方法make_request()必須用XX實例調用,但怎麼做?
è類型錯誤:不受約束的方法make_request()必須以實例作爲第一個參數(有STR,而不是實例)
我不想設定make_request方法爲靜態,我叫想從一個對象的實例中調用它。
示例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
我的代碼
""" """
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'