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:100:test_name:PASS
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

Installation

unity-test-parser can be installed with pip:

pip install unity-test-parser

Usage

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(results_file.read())

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

for test in results.test_iter():
    print("Test: {} Result was: {}".format(test.name(), 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(basic_results_file.read(), unity_test_parser.UNITY_BASIC)

fixture_results = unity_test_parser.TestResults(fixture_results_file.read(),
                                                unity_test_parser.UNITY_FIXTURE_VERBOSE)

Project details


Download files

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

Source Distribution

unity-test-parser-0.1.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unity_test_parser-0.1.1-py2.py3-none-any.whl (10.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file unity-test-parser-0.1.1.tar.gz.

File metadata

  • Download URL: unity-test-parser-0.1.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.0

File hashes

Hashes for unity-test-parser-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6a04aa69418ff2b68298addd569b24ef0a07203b7a3a9376304c15eab6bcdabf
MD5 3bfcff3dd6d72a19ef7569710cff057d
BLAKE2b-256 19885b4734cfeab1b913394426bb28777f59536a973bbcd9cfb46133ec554b8d

See more details on using hashes here.

File details

Details for the file unity_test_parser-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: unity_test_parser-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.0

File hashes

Hashes for unity_test_parser-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fb5ac328f56eb35e475a53becb25b704a3ee3f4587b30ba847537e9b7154cd70
MD5 2e73e5bbe0ce64b45a7125a95d803bf5
BLAKE2b-256 9606a399675894fea6084da260bbc7bf57b7347342c70b1042e1c45eb1b8ee80

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page