jmcnamara / pytest_c_testrunner

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

Home Page:http://pytest-c-testrunner.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using pytest as a testrunner for C unit test files

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

It includes documentation and working examples.

image

The tutorial shows how to extend pytest to collect C unit test files, execute them, capture the output and displays it.

$ sudo pip install pytest

$ make

$ py.test -v
========================= test session starts ==========================
platform darwin -- Python 2.7.2 -- py-1.4.20 -- pytest-2.5.2
collected 9 items

test/test_basic_integers.c:13: test_some_integers() PASSED
test/test_basic_integers.c:14: test_some_integers() PASSED
test/test_basic_integers.c:19: test_more_integers() FAILED
test/test_basic_integers.c:20: test_more_integers() FAILED
test/test_basic_strings.c:16: test_some_strings() PASSED
test/test_basic_strings.c:17: test_some_strings() FAILED
test/test_basic_strings.c:25: test_more_strings() FAILED
test/test_basic_strings.c:26: test_more_strings() FAILED
test/test_basic_strings.c:27: test_more_strings() PASSED

=============================== FAILURES ===============================
_________________________ test_more_integers() _________________________
Test failed : ASSERT_EQUAL_STR(313, 33) at test_basic_integers.c:19
         got: 33
    expected: 313

_________________________ test_more_integers() _________________________
Test failed : ASSERT_EQUAL_STR(12, 2) at test_basic_integers.c:20
         got: 2
    expected: 12

_________________________ test_some_strings() __________________________
Test failed : ASSERT_EQUAL_STR(foo, bar) at test_basic_strings.c:17
         got: This is bar
    expected: This is foo

_________________________ test_more_strings() __________________________
Test failed : ASSERT_EQUAL_STR(bar, bar + 1) at test_basic_strings.c:25
         got: his is bar
    expected: This is bar

_________________________ test_more_strings() __________________________
Test failed : ASSERT_EQUAL_STR(foo, NULL) at test_basic_strings.c:26
         got: (null)
    expected: This is foo

================== 5 failed, 4 passed in 0.23 seconds ==================

Read the full documentation.

About

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

http://pytest-c-testrunner.readthedocs.org/

License:Other


Languages

Language:C 42.5%Language:Python 41.7%Language:Makefile 15.8%