python - Pycharm 在使用 Python 的 pytest 框架进行测试时为测试生成奇怪的代码模板

标签 python unit-testing pycharm pytest

为什么 PyCharm 在单击“创建新测试..:”时生成以下代码模板,即使我将 pytest 作为我的默认测试运行器?

如果我的函数是create_training_data,那么 PyCharm 将为此生成以下代码:

from unittest import TestCase

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

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

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

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

最佳答案

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

关于python - Pycharm 在使用 Python 的 pytest 框架进行测试时为测试生成奇怪的代码模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54524736/

相关文章:

python - 如何根据 Pandas 中的真/假条件选择列

Python 未实现的方法与抽象方法,哪个更 Pythonic? PyCharm 不喜欢未在基类中实现的方法

python - 使用 Python 的维基百科爬虫

python - 属性错误 : 'str' object has no attribute 'strftime' when modifying pandas dataframe

java - eclipse 。手动运行测试并使用 "maven install"后的不同行为

node.js - 我怎样才能 Jest 用 es6(没有 typescript )模拟 Prisma 客户端?

angularjs - 如何模拟在提供者私有(private)函数中手动注入(inject)的 $window?

python - PyCharm 调试器卡在 "Collecting Data"

python - 如何在Pycharm中执行代码块科学模式

Python3 制作一个列表,按一定量递增,按一定量递减