pytest fixture

#fixture可以放在单独的测试文件里,如果希望多个测试文件共享fixture,可以在公共目录下新建一个conftest.py,将fixture放在其中。

import pytest

@pytest.fixture()
def some_data():
    return 1

def test_some_data(some_data):
    assert some_data==1
# 使用--setup-show 回溯fixture的执行过程
pytest -v --setup-show test_demo8.py

pytest将每个fixture的执行分成SETUP和TEARDOWN两部分,测试被夹在中间。

猜你喜欢

转载自www.cnblogs.com/nicole-zhang/p/11390229.html