pytest-fmu-filter
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
- Specify FMU files when running pytest:
pytest --fmus path/to/model1.fmu path/to/model2.fmu
- Mark test functions with the
fmu_filtermarker 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 Exchangeis_cs: Filter FMUs that support Co-Simulationis_se: Filter FMUs that support Scheduled Execution (FMI 3.0 only)
Variable-Related Filters
has_input: Filter FMUs that have any input variableshas_output: Filter FMUs that have any output variableshas_parameter: Filter FMUs that have any parameter variableswith_variables: Filter FMUs that have specific variable nameswith_inputs: Filter FMUs that have specific input variable nameswith_outputs: Filter FMUs that have specific output variable nameswith_parameters: Filter FMUs that have specific parameter variable nameshas_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.
Metadata
Release files for pytest-fmu-filter 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pytest_fmu_filter-0.1.3.tar.gz | 13.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_fmu_filter-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.1 kB
Release files / pytest_fmu_filter-0.1.3.tar.gz
| Download URL | pytest_fmu_filter-0.1.3.tar.gz |
|---|---|
| Size | 13.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cc10831965328df036d089b61234ccdadfa29c354e811e9793ffb34d239fc38
|
|
BLAKE2b-256 checksum How to use checksums |
b33e4dc400d06ccdbb04e1ea512f2a65c6645e4658b8e66d3feed5c187c571c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / pytest_fmu_filter-0.1.3-py3-none-any.whl
| Download URL | pytest_fmu_filter-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47c19a429dee7137aa8cd788a4a0413924e0b61127bc696f1d692d6bf14827a2
|
|
BLAKE2b-256 checksum How to use checksums |
b2b7a23627f8377c928aa1f506c6b41547bdaab13764e3180e760a33ac95846f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Security for pytest-fmu-filter 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.