Pytest【定制fixture】
在pytest中的fixture是在测试函数运行前后,由pytest执行的外壳函数,fixture中的代码可以定制,满足多变的测试需求:包括定义传入测试中的数据集、配置测试前系统的初始化状态、为批量测试提供数据源。 import pytest @pytest.fixture() def return_data(): return 1000 def test_someting(return_data): assert return_data == 1000 执行结果如下: (venv) E:\Programs\Python\Python_Pytest\TestScripts>pytest -v test_fixture.py ============= test session starts ==================================== platform win32 -- Python 3.7.3, pytest-4.5.0, py-1.8.0, pluggy-0.11.0 -- c:\python37\python.exe cachedir: .pytest_cache rootdir: E:\Programs\Python\Python_Pytest\TestScripts plugins: xdist-1.29.0, timeout-1.3.3,