代码之家  ›  专栏  ›  技术社区  ›  Digital_AI

如何解决-W0104:声明似乎没有效果(毫无意义的声明)

  •  0
  • Digital_AI  · 技术社区  · 3 年前

    我正在尝试从测试错误 __getitem__() 函数并获取 Pylint 针对它的调查结果。

    def test_check_error():
        with pytest.raises(Exception) as error_i:
            obj["output"]    # getting error for this line
        assert str(error_i.value) == "abc"
    

    但随着时间的推移 "W0104: Statement seems to have no effect (pointless-statement)"

    0 回复  |  直到 3 年前
        1
  •  0
  •   Pierre.Sassoulas phoibos    3 年前

    你不想使用这个值,所以它对你来说是一个假阳性,你应该禁用这样的消息:

    def test_check_error():
        with pytest.raises(Exception) as error_i:
            obj["output"]  # pylint: disable=pointless-statement
        assert str(error_i.value) == "abc"
    
    推荐文章