如何在pycharm里面运行pytest用例

pycharm运行三种方式

1.以xx.py脚本方式直接执行,当写的代码里面没用到unittest和pytest框架时,并且脚本名称不是以test_开头命名的,此时pycharm会以xx.py脚本方式运行

2.当脚本命名为test_xx.py时,用到unittest框架,此时运行代码,pycharm会自动识别到以unittest方式运行

eg: test.hello.py

import unittest

class Test1(unittest.TestCase):
    def test_hello(self):
        print("hello world!")

if __name__=="__main__":
    unittest.main()

  

 

 

 

3.以pytest方式运行,需要改该工程设置默认的运行器:file->Setting->Tools->Python Integrated Tools->项目名称->Default test runner->选择py.test

备注:pytest是可以兼容unittest框架代码的

posted on 2021-04-12 10:39  清明-心若淡定  阅读(920)  评论(0编辑  收藏  举报