Skip to content

jmcnamara/pytest_ctest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using pytest as a testrunner for CTEST unit test files

This is an simple tutorial on how to use the Python pytest testing tool as a testrunner for CTEST unit tests.

CTEST

CTEST is a C unit test framework. It is self contained in a single header file but also contains an integrated test runner.

It goes way beyond other macro based C unit tests frameworks while still providing a test collector and runner without external programs. It uses a large amount of C magic to do this but the end result is a lightweight yet fully functional C unit test framework.

It provides most of the functionality of GoogleTest or Unity but without the overhead of a large support framework or external scaffolding.

It also has nice clear output. Here is a example from the sample unit test in the CTEST repo:

image

Pytest

CTEST has its own test runner and, as already stated, it is standalone and doesn't need external scaffolding apart from a simple main().

Nevertheless, the example shown here used Pytest as a test runner for CTEST. This offers a small amount of additional functionality to CTEST and is presented mainly as a proof of concept.

Pytest is a really nice Python testing tool. It has great 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.

Pytest supports the creation of hooks in a file called conftest.py. This allows you to define, in Python, code to find test files, run them, and collect the results. The nice thing about this is that you can create a hook layer between pytest and the CTEST unit tests without changing code in either one.

Here is the same, unmodified, CTEST test case run under pytest:

image

Pytest allows a large range of filter and commandline options such as the following to give a minimal test output:

image

How it works

The pytest hooks are contained in the conftest.py program and are explained as a general concept in Using pytest as a testrunner for C unit tests.

About

Using py.test as a testrunner for CTEST unit test files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages