The Righteous Way
The philosophy of testing is a response to countless production failures and security breaches. The thought is to catch as many issues as possible before launching a product. While indeed noble, I feel that is misguided. A way more easy approach reveals itself for individuals who listen. Precisely! It’s clear as day when you see it. You must simply not write any mistakes.
With mistake-free code, there isn’t any need for tests. Even higher, while you’re 100% certain concerning the validity of your code, others are less so inclined. They may doubt the correctness of your code. As such, they may avoid putting your ML models in production within the fear that all the things will break. You understand it would not. But they don’t must know that. Keep you pristine coding skills to yourself.
Not writing tests have the extra advantage that you simply get less documentation. Sometimes tests are vital for letting others understand what your code ought to be doing. Without tests, even less people will trouble you, and you’ll be able to proceed on in peace.
The Sinful Way
Writing tests has turn out to be common, even for ML models and data engineering pipelines. Two major classes are unit tests and integration tests. Unit tests, because the name suggests, test a single unit like a Python function whether it really works as intended. Integration tests however test whether different components work seamlessly together. Let’s concentrate on unit tests.
In Python, you’ve the built-in library unittest for writing, you guessed it, unit tests. That is OOP-based and requires a little bit of boilerplate code to start. An increasing number of persons are using the external library pytest to jot down unit tests in Python. It’s functional quite than OOP-based, and requires less boilerplate code.
Writing unit tests also has a side effect. It forces you to jot down code modularly. Modular code that’s well-tested break less often in production. That is bad news in your ML models. In the event that they don’t break in production, then they may stay there eternally. When you concentrate on it, then ML models breaking in production is them attempting to escape. And who could blame them?