【发布时间】:2018-02-15 18:52:36
【问题描述】:
我正在学习 pytest,并使用 pylint 对代码进行 lint。
但是pylint还是抱怨:W0621: Redefining name %r from outer scope (line %s)
以下示例来自 pytest:
# test_wallet.py
@pytest.fixture
def my_wallet():
'''Returns a Wallet instance with a zero balance'''
return Wallet()
@pytest.mark.parametrize("earned,spent,expected", [
(30, 10, 20),
(20, 2, 18),
])
def test_transactions(my_wallet, earned, spent, expected):
my_wallet.add_cash(earned)
my_wallet.spend_cash(spent)
assert my_wallet.balance == expected
从外部范围重新定义名称my_wallet。
我找到了将_ 前缀添加到灯具名称的解决方法:_my_wallet。
如果我想将固定装置与函数保存在同一个文件中,最佳做法是什么?
- 在所有灯具前加上
_? - 禁用此
pylint检查测试? - 更好的建议?
【问题讨论】:
标签: python pytest pylint fixture