如何在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框架代码的


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM