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 .

If you want to write and run C unit tests then there are a lot of better alternatives such as Unity or GoogleTest (for C/C++ testing) or many others .

So, what is the use case?

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.