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

当使用python的pytest框架进行测试时,pycharm为测试生成奇怪的代码模板

  •  3
  • l7ll7  · 技术社区  · 6 年前

    为什么pycharm在单击“创建新测试…”时生成以下代码模板,即使我已经 pytest 作为我的默认测试运行程序?

    如果我的功能是 create_training_data ,然后pycharm将为此生成以下代码:

    from unittest import TestCase
    
    class TestCreate_training_data(TestCase):
        def test_create_training_data(self):
        self.fail()
    

    然而 脓包 既不需要导入,也不需要子类化,

    class TestCreate_training_data(object):
        def test_create_training_data(self):
        self.fail()
    

    这就足够了,因为“入门”页面已经显示: https://docs.pytest.org/en/latest/getting-started.html

    1 回复  |  直到 6 年前
        1
  •  0
  •   Pavel Karateev    6 年前

    Pycharm只知道如何创造 unittest 目前正在测试。请为相应的功能请求投票: PY-15021 .