Run tests

How to add a new test runner to the test goal.


Example repository

This guide walks through adding a simple test implementation for Bash that runs the shunit2 test runner. See here for the final implementation.

1. Set up a test target type

Usually, you will want to add a "test" target type for your language, such as shell_test or python_test. A test target contrasts with a "source" target, such as shell_source. A test target is useful so that ./pants test :: doesn't try to run tests on non-test files.

When creating a test target, you should usually subclass SingleSourceField. You may also want to create TimeoutField, which should subclass IntField.

See Creating new targets for a guide on how to define new target types.

from import (

class ShellSourceField(SingleSourceField):
    expected_file_extensions = (".sh",)

class ShellTestSourceField(SingleSourceField):

class ShellTestTimeoutField(IntField):
     alias = "timeout"
     help = "Whether to time out after a certain period of time."

class ShellTestTarget(Target):
    alias = "bash_tests"
    help = "Shell tests that are run via `shunit2`."
    core_fields = (*COMMON_TARGET_FIELDS, Dependencies, ShellTestSourceField, ShellTestTimeoutField)

2. Set up a subclass of TestFieldSet

Did this page help you?