DIY Factories with Pytest

Pytest’s fixtures are a pretty convenient route to dependency injection throughout your tests. They’re flexible, too, and involve very little “magic.” This means they’re easy to learn, understand, and use correctly. The Pytest documentation explains that a fixture can pass back anything to the caller, including a function. This allows you to essentially create parameterized […]

Using the Command Pattern to Write More Testable Python

Often times, when writing Python, I run into a situation that requires me to write a simple validation function. def check_validity(item): return item.value_to_check > 0def check_validity(item): return item.value_to_check > 0 This function is easy to test, and it’s clear what it’s supposed to be doing. But as so often happens, I may need to validate […]