def filter_fixtures(all_fixtures, fixtures_base_dir, mark_fn=None, ignore_fn=None):
"""
Helper function for filtering test fixtures.
- `fixtures_base_dir` should be the base directory that the fixtures were collected from.
- `mark_fn` should be a function which either returns `None` or a `pytest.mark` object.
- `ignore_fn` should be a function which returns `True` for any fixture
which should be ignored.
"""
for fixture_data in all_fixtures:
fixture_path = fixture_data[0]
fixture_relpath = os.path.relpath(fixture_path, fixtures_base_dir)
if ignore_fn:
if ignore_fn(fixture_relpath, *fixture_data[1:]):
continue
if mark_fn is not None:
mark = mark_fn(fixture_relpath, *fixture_data[1:])
if mark:
yield pytest.param(
(fixture_path, *fixture_data[1:]),
marks=mark,
)
continue
yield fixture_data
评论列表
文章目录