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.8 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

Contributing

Contributions are very welcome! Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

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.1.tar.gz (13.9 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.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest_fmu_filter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c29e167a4150257ba2ae9783cce775faffb054eb2ee04c0f19ef1bc2329c8148
MD5 0d28d2eb5b647930e1227de7585ed57e
BLAKE2b-256 ec032c7f6995387e9bf0a48998844ad3a6aa677c881be26ad3c4ba33c81b624a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_fmu_filter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4489c37ac8a0f5c2fdf51ab49a561b0d5e3173087e75c83198ade1056a41881
MD5 be457f534a7a97e0928c402fdc6eced4
BLAKE2b-256 c542fc9803211a53bb472538ed3d107049aafa3f5c097b325d10c1e0bdbcfe30

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