运行下面的代码我得到
E TypeError: unbound method make_request() must be called with A instance as first argument (得到 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'