官方用例
# content of myivoke.py
import sys
import pytest
class MyPlugin:
def pytest_sessionfinish(self):
print("*** test run reporting finishing")
if __name__ == "__main__":
sys.exit(pytest.main(["-qq"],plugins=[MyPlugin()]))
# content of other_invoke.py
import pytest
if __name__ == "__main__":
retcode = pytest.main()
print(retcode)
# content of test_invok_01.py
def test_invok_01():
print("test_invok_01 was invoked")
assert 0
解读与实操
- 通过pytest命令行调用
- 通过python命令行调用
- python代码中调用
应用场景
- 个人调试或Jenkins调用,可使用python或pytest命令行
- 测试平台,集成pytest时,可以在Python代码中调用pytest