Using Multiple Fixtures

You’ve already seen that tmpdir uses tmpdir_factory. And you used tmpdir in our tasks_db fixture. Let’s keep the chain going and add some specialized fixtures for non-empty tasks databases:

 @pytest.fixture()
 def​ db_with_3_tasks(tasks_db, tasks_just_a_few):
 """Connected db with 3 tasks, all unique."""
 for​ t ​in​ tasks_just_a_few:
  tasks.add(t)
 
 
 @pytest.fixture()
 def​ db_with_multi_per_owner(tasks_db, tasks_mult_per_owner):
 """Connected db with 9 tasks, 3 owners, all with 3 tasks."""
 for​ t ​in​ tasks_mult_per_owner:
  tasks.add(t)

These fixtures all include two fixtures each in their parameter list: tasks_db and a data set. The data set is used to add tasks to ...

Get Python Testing with pytest now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.