This document shows how to use the Python pytest test tool to run unit tests written in C.
I’m going to show you how to run C unit tests using the Python test tool pytest.
No. I’m pretty sure it isn’t.
Established C test frameworks are a better alternative when you are starting a project from scratch. However, if you have existing C unit tests that you just want to execute, then rewriting them to conform to a new framework probably isn’t worth the effort.
Equally, writing a testrunner that is flexible enough to run all or a subset of the tests, that can output the results in JUnit or other formats, or that can filter results into concise reports probably isn’t worth the effort either.
In which case it would be better to use an existing testrunner that supports all these features and that can be easily extended to capture the output from existing C unit tests without having to modify them.
Pytest is a really nice Python testing tool.
It has good documentation, clean code, lots of tests, a large but clear set of options for running tests and collecting results and best of all it is easily extensible.
Then read on and I’ll see if I can convince you with a working example.
So let’s start with The C Unit Tests.