前言
我们在看见每个项目都有个入口文件,用来启动项目,但是在我们的自动化项目里面,特别是前面使用过unittest框架的人来说特别熟悉,在项目新建一个 main.py
或者 run_all.py
文件,使用python main.py
或者python run_all.py
执行测试。
在pytest框架也有一个入口,那就是 pytest.main()
,可以作为用例执行入口,下面我们对pytest.main()
进行讲解。
pytest.main()
pytest.main()
源码
def main(
args: Optional[Union[List[str], py.path.local]] = None,
plugins: Optional[Sequence[Union[str, _PluggyPlugin]]] = None,
) -> Union[int, ExitCode]:
"""Perform an in-process test run.
:param args: List of command line arguments.
:param plugins: List of plugin objects to be auto-registered during initialization.
:returns: An exit code.
"""
try:
try:
config = _prepareconfig(args, plugins)
except ConftestImportFailure as e:
exc_info = ExceptionInfo(e.excinfo)
tw = T