Is it possible to use python to unit test C++ code?

skip at pobox.com skip at pobox.com
Wed Dec 21 10:49:54 EST 2005


    sylcheung> Is it possible to use python to unit test C++ code? If yes,
    sylcheung> is there any example available?

Yes, it's quite possible.  Some people even do it. ;-) As for examples, take
a look at Python's own test suite.  Much of the code it contains actually
tests modules written in C, which is near enough to C++ for our purposes.
For example, consider that the math module is a thin wrapper around bits of
standard C89 math functions.  The test_math.py script then exercises that
code.

So, you'll have to wrap your C++ library to make it available in Python
(check out SWIG and/or Boost and/or Python's Extending and Embedding
documentation), then write test cases.  For that, look at the unittest and
doctest modules that come with Python as well as the third-party py.test
package.

Skip




More information about the Python-list mailing list