测试人社区

求教:完成python实战二作业遇到 AttributeError: 'Function' object has no attribute 'add_maker'问题

conftest.py文件中代码如下
def pytest_collection_modifyitems(session,config,items:list):
for item in items:
if “add” in item.nodeid:
item.add_maker(pytest.mark.add)
elif “div” in item.nodeid:
item.add_maker(pytest.mark.div)
elif “mul” in item.nodeid:
item.add_maker(pytest.mark.mul)
elif “sub” in item.nodeid:
item.add_maker(pytest.mark.sub)

testpytest.py代码如下:
import yaml
from allurepython.demo1 import demo1
import pytest
class TestCalc:
@pytest.mark.parametrize((‘a’,‘b’),[(1,2),(2,1),(0,0),(-1,-2),(-2,-1),(100.0,200.0)])
def test_add_1(self,a,b):
self.demo1=demo1()
result=self.demo1.add(a,b)
print(result)
assert (a+b)==result
@pytest.mark.parametrize((“a”,“b”),yaml.safe_load(open("./data.yaml")))
def test_div_1(self,a,b):
try:
self.demo1 = demo1()
result = self.demo1.div(a,b)
print(result)
assert (a/b) == result
except ValueError as e:
assert False
print(e)

项目目录如下:
image

运行testpytest.py时报错
INTERNALERROR> AttributeError: ‘Function’ object has no attribute ‘add_maker’

请格式化你的代码,你这样的代码属实看的很痛苦

方法名字叫 add_marker 你打错了
image

确实,感谢指正