gpt4 book ai didi

python - 是否可以在 PyCharm 中生成 py.test 测试文件?

转载 作者:太空宇宙 更新时间:2023-11-04 04:37:53 25 4
gpt4 key购买 nike

假设我有一个包含以下内容的 app.py 文件:

def foo():
return 'bar'

即使在 PyCharm 中将 py.test 设置为默认测试运行程序(设置 -> 工具 -> Python 集成工具),PyCharm 始终生成 unittest 类测试(右键单击函数名称 -> Go To -> Test -> Create New Test),例如:

from unittest import TestCase

class TestFoo(TestCase):
def test_foo(self):
self.fail()

我可以在 Setting -> Editor -> File and Code Templates 中更改 Python Unit Test 模板,但它只在创建新文件时有效(New -> Python 文件 -> 种类:Python 单元测试).

我希望生成的测试更像py.test:

def test_foo():
assert False

更好的方法是将适当的 import 放入:

from my_app import foo

def test_foo():
assert False

最佳答案

很遗憾,这是不可能的。请在 PyCharms 的错误跟踪器中为相应的功能请求投票:PY-15021 .

关于python - 是否可以在 PyCharm 中生成 py.test 测试文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51266814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com