前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Pytest脚本中用例运行方式

Pytest脚本中用例运行方式

作者头像
王大力测试进阶之路
发布2019-11-09 17:23:06
1K0
发布2019-11-09 17:23:06
举报
文章被收录于专栏:橙子探索测试橙子探索测试

脚本树如下:

test1文件下test_01.py存放test1和test2用例

test1文件下test_02.py存放test1和test2用例

test2文件下test_03.py存放test1和test2用例

test2文件下test_04.py存放test1和test2用例

代码语言:javascript
复制
1、运行所有用例import pytestif __name__ == "__main__":    pytest.main(['-s',''])  "C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/PytestAutomation/testcase/run_all_test.py============================= test session starts =============================platform win32 -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcaseplugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0collected 8 items test1\test_01.py 调用了获取tokentest_01-test1:5.test_01-test2:5.test1\test_02.py test_02-test1:5.test_02-test2:5.test2\test_03.py test_03-test1:5.test_04-test2:5.test2\test_04.py test04-test1:5.test04-test2:5. ============================== 8 passed in 0.25s ============================== Process finished with exit code 0-------------------------------------------------------------------------------------- 2、运行指定文件夹下用例import pytestif __name__ == "__main__":    pytest.main(['-s','test1']) "C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/PytestAutomation/testcase/run_all_test.py============================= test session starts =============================platform win32 -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcaseplugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0collected 4 items test1\test_01.py 调用了获取tokentest_01-test1:5.test_01-test2:5.test1\test_02.py test_02-test1:5.test_02-test2:5. ============================== 4 passed in 0.12s ============================== Process finished with exit code 0 ----------------------------------------------------------------------------------- 3、运行指定py文件下用例import pytestif __name__ == "__main__":    pytest.main(['-s','test1/test_01.py']) "C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/PytestAutomation/testcase/run_all_test.py============================= test session starts =============================platform win32 -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcaseplugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0collected 2 items test1\test_01.py 调用了获取tokentest_01-test1:5.test_01-test2:5. ============================== 2 passed in 0.04s ============================== Process finished with exit code 0  4、运行指定类下的用例import pytestif __name__ == "__main__":    pytest.main(['-s','test1/test_01.py::Test'])  "C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/PytestAutomation/testcase/run_all_test.py============================= test session starts =============================platform win32 -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcaseplugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0collected 2 items test1\test_01.py 调用了获取tokentest_01-test1:5.test_01-test2:5. ============================== 2 passed in 0.04s ============================== Process finished with exit code 0 -------------------------------------------------------------------------------------  5、运行执行方法下的用例import pytestif __name__ == "__main__":    pytest.main(['-s','test1/test_01.py::Test::test1']) "C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/PytestAutomation/testcase/run_all_test.py============================= test session starts =============================platform win32 -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcaseplugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0collected 1 item test1\test_01.py 调用了获取tokentest_01-test1:5. ============================== 1 passed in 0.04s ============================== Process finished with exit code 0 
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-11-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 橙子探索测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档