默認狀況下,pytest會遞歸查找當前目錄下全部以
test
開始或結尾的Python
腳本,並執行文件內的全部以test
開始或結束的函數和方法.html
etc ├── robocop.toml ├── test_data.py └── test_demo.py
test
打頭的py文件中test
打頭的函數(測試用例)╰ pytest -v etc =================================================== test session starts ==================================================== platform darwin -- Python 3.7.4, pytest-4.4.0, py-1.8.0, pluggy-0.13.0 -- /Users/zhouwanghua/Code/Leyan/python/robocop/bin/python cachedir: .pytest_cache metadata: {'Python': '3.7.4', 'Platform': 'Darwin-18.6.0-x86_64-i386-64bit', 'Packages': {'pytest': '4.4.0', 'py': '1.8.0', 'pluggy': '0.13.0'}, 'Plugins': {'bdd': '3.1.0', 'html': '1.20.0', 'metadata': '1.8.0'}} rootdir: /Users/zhouwanghua/Code/Leyan/robocop, inifile: pytest.ini plugins: bdd-3.1.0, html-1.20.0, metadata-1.8.0 collected 4 items etc/test_data.py::test_data1 PASSED [ 25%] etc/test_data.py::test_data2 PASSED [ 50%] etc/test_demo.py::test_demo PASSED [ 75%] etc/test_demo.py::test_demo2 PASSED ================================================= 4 passed in 0.01 seconds =================================================
╰ pytest -v etc/test_demo.py =================================================== test session starts ==================================================== platform darwin -- Python 3.7.4, pytest-4.4.0, py-1.8.0, pluggy-0.13.0 -- /Users/zhouwanghua/Code/Leyan/python/robocop/bin/python cachedir: .pytest_cache metadata: {'Python': '3.7.4', 'Platform': 'Darwin-18.6.0-x86_64-i386-64bit', 'Packages': {'pytest': '4.4.0', 'py': '1.8.0', 'pluggy': '0.13.0'}, 'Plugins': {'bdd': '3.1.0', 'html': '1.20.0', 'metadata': '1.8.0'}} rootdir: /Users/zhouwanghua/Code/Leyan/robocop, inifile: pytest.ini plugins: bdd-3.1.0, html-1.20.0, metadata-1.8.0 collected 2 items etc/test_demo.py::test_demo PASSED [ 50%] etc/test_demo.py::test_demo2 PASSED ================================================= 2 passed in 0.01 seconds =================================================
╰ pytest -v etc/test_demo.py::test_demo2 =================================================== test session starts ==================================================== platform darwin -- Python 3.7.4, pytest-4.4.0, py-1.8.0, pluggy-0.13.0 -- /Users/zhouwanghua/Code/Leyan/python/robocop/bin/python cachedir: .pytest_cache metadata: {'Python': '3.7.4', 'Platform': 'Darwin-18.6.0-x86_64-i386-64bit', 'Packages': {'pytest': '4.4.0', 'py': '1.8.0', 'pluggy': '0.13.0'}, 'Plugins': {'bdd': '3.1.0', 'html': '1.20.0', 'metadata': '1.8.0'}} rootdir: /Users/zhouwanghua/Code/Leyan/robocop, inifile: pytest.ini plugins: bdd-3.1.0, html-1.20.0, metadata-1.8.0 collected 1 item etc/test_demo.py::test_demo2 PASSED [100%] ================================================= 1 passed in 0.01 seconds =================================================