Skip to main content

A pytest plugin to filter fmus

Project description

pytest-fmu-filter

PyPI version Python versions See Build Status on GitHub Actions

A pytest plugin to filter and parameterize tests with FMU (Functional Mock-up Unit) files.

Overview

pytest-fmu-filter is a pytest plugin that allows you to easily filter and run tests against specific FMU files based on various criteria. This is particularly useful for testing simulation models that follow the Functional Mock-up Interface (FMI) standard.

The plugin allows you to:

  • Specify FMU files via command line arguments
  • Filter FMUs based on specific criteria such as:
    • Model Exchange (ME) or Co-Simulation (CS) interface type
    • Presence of inputs or outputs
    • Name patterns
    • Custom filter functions

When/Why to Use

pytest-fmu-filter is ideal for cases where you have multiple FMU files and want to selectively run tests against them based on their properties. This can help you:

  • Focus on specific models that are relevant to your current testing needs
  • Avoid running tests on FMUs that do not meet certain criteria, saving time and resources

Requirements

  • Python 3.10 or higher
  • pytest 7.0.0 or higher

Installation

Install "pytest-fmu-filter" with uv (to dev group):

uv add pytest-fmu-filter --dev

Usage

Basic Usage

  1. Specify FMU files when running pytest:
pytest --fmus path/to/model1.fmu path/to/model2.fmu
  1. Mark test functions with the fmu_filter marker to apply filters:
import pytest

@pytest.mark.fmu_filter(is_me=True)  # Only run with Model Exchange FMUs
def test_model_exchange_fmu(fmu):
    # Your test code here
    assert fmu is not None

Available Filter Options

The following filter options are supported in the fmu_filter marker:

Interface Type Filters

  • is_me: Filter FMUs that support Model Exchange
  • is_cs: Filter FMUs that support Co-Simulation
  • is_se: Filter FMUs that support Scheduled Execution (FMI 3.0 only)

Variable-Related Filters

  • has_input: Filter FMUs that have any input variables
  • has_output: Filter FMUs that have any output variables
  • has_parameter: Filter FMUs that have any parameter variables
  • with_variables: Filter FMUs that have specific variable names
  • with_inputs: Filter FMUs that have specific input variable names
  • with_outputs: Filter FMUs that have specific output variable names
  • with_parameters: Filter FMUs that have specific parameter variable names
  • has_array_variables: Filter FMUs that have array variables (FMI 3.0 only)

Model Information Filters

  • name_matches: Filter FMUs by regex pattern matching the model name

Custom Filters

  • custom: Provide a custom filter function that takes a ModelDescription object

Examples:

# Filter by interface type
@pytest.mark.fmu_filter(is_cs=True)
def test_cosimulation_fmu(fmu):
    # Test will only run with FMUs that support Co-Simulation
    pass

# Filter by variable existence
@pytest.mark.fmu_filter(has_input=True, has_output=True)
def test_fmu_with_io(fmu):
    # Test will only run with FMUs that have both inputs and outputs
    pass

# Filter by specific variable names
@pytest.mark.fmu_filter(with_inputs=["position", "velocity"])
def test_position_control(fmu):
    # Test will only run with FMUs that have input variables named "position" and "velocity"
    pass

# Filter by name pattern
@pytest.mark.fmu_filter(name_matches="Robot.*Controller")
def test_robot_controller(fmu):
    # Test will only run with FMUs that have names matching the regex "Robot.*Controller"
    pass

# Combine multiple filters
@pytest.mark.fmu_filter(is_me=True, has_parameter=True, name_matches=".*Model.*")
def test_parameterized_model(fmu):
    # Test will only run with Model Exchange FMUs that have parameters and "Model" in their name
    pass

License

Distributed under the terms of the MIT license, "pytest-fmu-filter" is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

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

pytest_fmu_filter-0.1.3.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

pytest_fmu_filter-0.1.3-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_fmu_filter-0.1.3.tar.gz.

File metadata

  • Download URL: pytest_fmu_filter-0.1.3.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for pytest_fmu_filter-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1cc10831965328df036d089b61234ccdadfa29c354e811e9793ffb34d239fc38
MD5 10140d606ec74652ad3d820be78a251a
BLAKE2b-256 b33e4dc400d06ccdbb04e1ea512f2a65c6645e4658b8e66d3feed5c187c571c0

See more details on using hashes here.

File details

Details for the file pytest_fmu_filter-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_fmu_filter-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 47c19a429dee7137aa8cd788a4a0413924e0b61127bc696f1d692d6bf14827a2
MD5 16876c29e68f8d2ab4d5dc712a959c16
BLAKE2b-256 b2b7a23627f8377c928aa1f506c6b41547bdaab13764e3180e760a33ac95846f

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