''' 模块级(setup_module/teardown_module)开始于模块始末, 全局的在类中不起作用 类级(setup_class/teardown_class)只在类中前后运行一次(在 类中) 方法级(setup_method/teardown_method)开始于方法始末 (在类中) 函数级(setup_function/teardown_function只对函数用例生 效(在类中不生效) setup_function teardown_function ''' import pytest def setup_function(): print() print("setup_function:class外的每个用例前开始执行") def teardown_function(): print("teardown_function:class外的每个个用例后开始执行") def setup_module(): """ 这是一个module级别的setup,它会在本module(test_fixt_class.py)里 所有test执行之前,被调用一次。 注意,它是直接定义为一个module里的函数""" print() print("-------------- setup before module --------------") def
pytest_用例运行级别_class级
最新推荐文章于 2023-09-22 15:18:57 发布
本文详细介绍了pytest在执行测试用例时,针对类级别的设置和执行顺序。从setup_module到teardown_module,再到setup_class、setup_method、teardown_method等各个阶段的执行过程,并通过实例展示了每个阶段在测试用例执行前后的行为。
摘要由CSDN通过智能技术生成