Skip to content

Adding py.test to ctest

Mayeul d'Avezac edited this page Aug 12, 2014 · 3 revisions

A function is provided to run py.test through the ctest runner. This is a two step process:

  1. Find or install py.test, as well as a script to run it inside the build directory
  2. Add the tests
include(AddPyTest)

# Finds/install py.test
setup_pytest(
    # Path where pytest will be installed, e.g. "${EXTERNAL_ROOT}/python"
    <python path>
    # Path to a script to run the tests inside the build directory
    # e.g. "${PROJECT_BINARY_DIR}/py.test.sh"
    # This script will know about the paths added by add_to_python_path
    <py.tests.sh path>
)

# Add tests
add_pytest(
   # Source files or patterns to discover test files
   # could be "test_*.py this.py"
   <sources or  patterns>
   # Sources or patterns to exclude from testing
   [EXCLUDE <source> <source>]
   [WORKING_DIRECTORY <path>]
   # A test "test_this.py" will appear in cmake as "${prefix}.this"
   # Prefix is empty by default
   [PREFIX <prefix>]
   # Additional labels on top of "python" and "py.test"
   [LABELS <label> <label>]
   # Commandline arguments to pass to py.test
   [CMDLINE <arg> <arg>]
)