Parametrizing Fixtures
In Parametrized Testing, we parametrized tests. We can also parametrize fixtures. We still use our list of tasks, list of task identifiers, and an equivalence function, just as before:
| import pytest |
| import tasks |
| from tasks import Task |
| |
| tasks_to_try = (Task('sleep', done=True), |
| Task('wake', 'brian'), |
| Task('breathe', 'BRIAN', True), |
| Task('exercise', 'BrIaN', False)) |
| |
| task_ids = ['Task({},{},{})'.format(t.summary, t.owner, t.done) |
| for t in tasks_to_try] |
| |
| |
| def equivalent(t1, t2): |
| """Check two tasks for equivalence.""" |
| return ((t1.summary == t2.summary) and |
| (t1.owner == t2.owner) and |
| (t1.done == t2.done)) |
But now, ...
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.