blog.md

There are plenty of instances in which boilerplate code is written. One of these may involve checking the types of multiple function or method calls, which can lead to situations like the following. Consider the [Stocks] (https://iextrading.com/developer/docs/#stocks) endpoints of IEX as used in iexfinance. There are many, many endpoints like Book, Chart, and Dividends.

Problem: Boilerplate Code

https://gist.github.com/04960fbe517ef448a2052d06df83d68b

It’s clear here that we are running assert isinstance(data, pd.DataFrame) in each test method. What's the best way to clear this up? Surely we can write this in less code.

Solution: Parametrize with pytest.mark.parametrize

With pytest.mark.parametrize, we can store the value of each function call. Let's use a more general example to display how this works. Consider the class foo:

https://gist.github.com/e0cccf415178b735297d3f653f369b3c

Say we’d like to test the functionality of a, b, and c.

https://gist.github.com/89f0a1ca6cabc90e2533ab7ee921dd90

This uses a significant amount less code.