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

时间:2018-07-10 13:40:12

标签: python pycharm pytest

假设我有一个app.py文件,内容如下:

def foo():
    return 'bar'

即使将py.test设置为PyCharm(Settings -> Tools -> Python Integrated Tools)的默认测试运行程序,PyCharm也会始终生成类似unittest的测试(right-click on a function name -> Go To -> Test -> Create New Test),例如:

from unittest import TestCase

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

我可以在Python Unit Test中更改Setting -> Editor -> File and Code Templates模板,但是它仅在创建新文件(New -> Python File -> Kind: Python unit test)时有效。

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

def test_foo():
    assert False

更好的做法是将适当的import放置在以下位置:

from my_app import foo

def test_foo():
    assert False

1 个答案:

答案 0 :(得分:1)

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

相关问题