python测试框架选择(Python测试框架pytest02PyCharm运行pytest)
1、PyCharm设置运行pytest
2、pytest.main()
2.1、带参数运行
2.2、运行指定用例
2.3、加载指定插件
1、PyCharm设置运行pytest打开PyCharm,依次打开Preferences--->Tools--->Python Integrated Tools,将Testing里的Default test runner选择项选为pytest,保存即可。
右键运行,可以看到以pytest去运行。
2、pytest.main()
main 函数有2个可选参数:
args:命令行参数列表。
plugins:初始化期间要自动注册的插件对象列表。
pytest.main() 不带任何参数时与在命令行直接运行 pytest 命令一样,默认运行的是当前目录及子目录的所有文件夹的测试用例。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
AllTests软件测试
"""
import pytest
pytest.main()
2.1、带参数运行
1、在命令行运行pytest -s
在pytest.main()里面等同于
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
AllTests软件测试
"""
import pytest
pytest.main(["-s"])
2、在命令行运行pytest -s -x
在pytest.main()里面等同于
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
AllTests软件测试
"""
import pytest
pytest.main(["-s", "-x"])
2.2、运行指定用例
1、命令行跳转到项目根目录,执行test/case文件夹下的全部用例
pytest test/case
在pytest.main()里面等同于
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
AllTests软件测试
"""
import pytest
pytest.main(["test/case"])
2、命令行跳转到项目根目录,执行test/case/test_case1.py文件里的全部用例
pytest test/case/test_case1.py
在pytest.main()里面等同于
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
AllTests软件测试
"""
import pytest
pytest.main(["test/case/test_case1.py"])
3、命令行跳转到项目根目录,执行test/case/test_case1.py文件里的test_login用例
pytest test/case/test_case1.py::test_login
在pytest.main()里面等同于
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
AllTests软件测试
"""
import pytest
pytest.main(["test/case/test_case1.py::test_login"])
2.3、加载指定插件
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
AllTests软件测试
"""
import pytest
pytest.main(["test/case"], plugins=[插件名])
公众号:AllTests软件测试
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com