Code Challenge 39 - Writing Tests With Pytest

PyBites, Thu 05 October 2017, Challenge

BetterCodeHub, CI, fixtures, Hacktoberfest, opensource, pytest, pytest-cov, TalkPython, testing, unittest

Life is about facing new challenges - Kostya Tszyu

Hi Pythonistas, let's add some more challenges for October. Following our Python testing with pytest book review we let you write some tests with this awesome framework.

The Challenge

Here are some options:

  1. Add tests for one of your repos that lacks tests. You can use BetterCodeHub to see how badly a project needs tests.

  2. Use pytest to add tests for a simple Flask API, code here.

  3. As mentioned in Talk Python #132: Contributing to open source, testing and documentation are great ways to contribute to open source. So like option 1. you could add tests to an open source project you like. Not only does this improve your understanding of the code, you also get to give something back, learning pytest as you go. Besides, as stated in challenge #38: this month any PR also counts towards Hacktoberfest.

Any tests will do, the purpose of this challenge is to get your feet wet with pytest. However you probably get the most out of this challenge if you play a bit with fixtures and other features/use cases.



To get credit PR your work to our Community branch of our Challenges repo. See detailed instructions here.


Our goal is to learn and teach you Python through practical exercises. Learning a programming language is way more fun as a community!

For any feedback, issues or ideas use GH Issues, tweet us or drop us an email.

Keep Calm and Code in Python!

-- PyBites

PyBites Python Tips

Do you want to get 250+ concise and applicable Python tips in an ebook that will cost you less than 10 bucks (future updates included), check it out here.

Get our Python Tips Book

"The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H

"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier." - Jesse B

"This is now my favourite first Python go-to reference." - Anthony L

"Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that." - Sergio S

Get the book