avatar Bite 249. Test a movie DB class

Note this is a Test Bite and uses Python 3.7 and MutPy 0.6.1

Time for fixtures, one of pytest's killer features or as Brian Okken said: pytest fixtures are one of the unique core features that make pytest stand out above other test frameworks, and are the reason why many people switch to and stay with pytest (Python Testing with pytest).

Why fixtures? The purpose of test fixtures is to provide a fixed baseline upon which tests can reliably and repeatedly execute. pytest fixtures offer dramatic improvements over the classic xUnit style of setup/teardown functions (docs).

In this Bite we wrote a little movie DB using sqlite3. The idea is that you write a db fixture to instantiate this class and run its init method to get the movies table created and populated. At the end of the fixture you use drop_table to undo any changes.

Apart from this setup and teardown there are 3 methods you need to test: query, add and delete. Specially query has various args, so make sure you test them all.

Apart from the docs we also wrote an article on fixtures you might want to check out: All You Need to Know to Start Using Fixtures in Your pytest Code.

Let us know on Twitter when you finish our pytest learning path ... Good luck and keep calm and code in Python / pytest!

Login and get coding
go back Advanced level
Bitecoin 4X

65 out of 65 users completed this Bite.
Will you be Pythonista #66 to crack this Bite?
Resolution time: ~88 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 6.5 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help