Skip to main content

Parse the output of the Unity Test Framework for C

Project description

Unity Test Parser

Build Status

A Python 3 module for parsing the console output of the Unity Test Framework. Unity (not to be confused with the far more popular graphics framework) is a unit testing framework optimized for embedded C. This module is intended to solve a couple of problems related to using Unity and to unit testing embedded apps in general:

  • Unity does not have a built-in method for generating XML or HTML output which can be parsed by CI systems.
  • Unity tests are often run in a simulator or directly on target hardware, where the exit code of the test process cannot be captured. In these cases, parsing the output is often the only possible method for determining whether the tests passed or failed.

This module can parse the output of basic Unity tests, of the form:

path/to/file.c:101:other_test_name:FAIL: Expected 1 Was 2

It can also parse the output of the Unity Fixture add-on, which groups tests into test groups or "fixtures":

TEST(group, test_name)path/to/file.c:100::FAIL: Expected 1 Was 2


unity-test-parser can be installed with pip:

pip install unity-test-parser


Getting Started

Use the UnityTestResults object to do the initial parsing of Unity test output. Assuming your test output is in a file, you can do:

import unity_test_parser

with open("results_file.txt", "r") as results_file:
    # This will raise ValueError if the results are improperly formatted
    results = unity_test_parser.TestResults(

You can inspect the individual tests, each represented by a UnityTest object:

for test in results.test_iter():
    print("Test: {} Result was: {}".format(, test.result()))

To convert the tests to JUnit XML:

import junit_xml

with open("test_results.xml", "w") as out_file:
    junit_xml.TestSuite.to_file(out_file, [results.to_junit()])

Test Results Format

Currently two types of Unity output are supported for parsing: The output of Unity used on its own (UNITY_BASIC) and the output of the unity_fixture extra invoked with the -v flag (UNITY_FIXTURE_VERBOSE). Use the second __init__ argument to the TestResults object to specify which format is being parsed. UNITY_BASIC is the default. If the results are in an invalid format, ValueError is raised.

results = unity_test_parser.TestResults(, unity_test_parser.UNITY_BASIC)

fixture_results = unity_test_parser.TestResults(,

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for unity-test-parser, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size unity_test_parser-0.1.1-py2.py3-none-any.whl (10.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size unity-test-parser-0.1.1.tar.gz (11.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page