Pytest脚本中运行用例方式
生活随笔
收集整理的這篇文章主要介紹了
Pytest脚本中运行用例方式
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
腳本樹如下:
test1文件下test_01.py存放test1和test2用例
test1文件下test_02.py存放test1和test2用例
test2文件下test_03.py存放test1和test2用例
test2文件下test_04.py存放test1和test2用例
1、運(yùn)行所有用例 import pytest if __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.0 rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcase plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collected 8 itemstest1\test_01.py 調(diào)用了獲取token test_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、運(yùn)行指定文件夾下用例 import pytest if __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.0 rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcase plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collected 4 itemstest1\test_01.py 調(diào)用了獲取token test_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、運(yùn)行指定py文件下用例 import pytest if __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.0 rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcase plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collected 2 itemstest1\test_01.py 調(diào)用了獲取token test_01-test1:5 .test_01-test2:5 .============================== 2 passed in 0.04s ==============================Process finished with exit code 04、運(yùn)行指定類下的用例 import pytest if __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.0 rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcase plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collected 2 itemstest1\test_01.py 調(diào)用了獲取token test_01-test1:5 .test_01-test2:5 .============================== 2 passed in 0.04s ==============================Process finished with exit code 0-------------------------------------------------------------------------------------5、運(yùn)行執(zhí)行方法下的用例 import pytest if __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.0 rootdir: C:\Users\wangli\PycharmProjects\PytestAutomation\testcase plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collected 1 itemtest1\test_01.py 調(diào)用了獲取token test_01-test1:5 .============================== 1 passed in 0.04s ==============================Process finished with exit code 0?
?
總結(jié)
以上是生活随笔為你收集整理的Pytest脚本中运行用例方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎样考计算机教师资格证书,非师专生怎么考
- 下一篇: python 安装echarts