#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

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

 

相关文章:

  • 2021-06-11
  • 2021-09-15
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2022-02-15
  • 2022-03-08
猜你喜欢
  • 2021-07-20
  • 2021-12-27
  • 2022-12-23
  • 2021-11-30
  • 2021-04-28
  • 2022-02-15
  • 2021-12-18
相关资源
相似解决方案