Python - 如何访问夹具属性

问题描述 投票:0回答:1

我正在尝试访问固定装置内的属性,如何访问它。

竞赛.py

@pytest.fixture(scope="session")
def numbers():
    one = 1
    two = 2
    total = one+two
    return total
    

num.py

def test(numbers):
    print("total = ",numbers.one)

上面出现以下错误

AttributeError: 'int' object has no attribute 'one'

如果我打印“数字”,我得到的答案是 3,但是如何访问固定功能内的变量。

python pytest
1个回答
0
投票
def test(numbers):
print(numbers())

刚刚在函数内部声明的变量在函数外部不可访问。

© www.soinside.com 2019 - 2024. All rights reserved.