Skip to content

swag-engineering/pytest-simbind

Repository files navigation

pytest-simbind

pytest-simbind is pytest plugin that facilitates SiL testing of Simbind objects. For a ready-to-use service solution refer to Simtest.

Specially, pytest-simbind allows to overcome main limitation of Simbind generated objects:

Due to the nature of binding technology you can instantiate Model class only once within a single process, all consequent instances will have the same state(time, input, and output props) as the first instance. If you need to instantiate multiple objects we recommend doing it in separate processes.

The core plugin integrates with pytest in an almost seamless manner, requiring only two simple steps from the user:

  • Decorate Simbind model fixture with @pytest_simbind.fixture. This helps pytest to keep track on Simbind fixture lifecycle and is mandatory if you need to use plugin's API.
  • Mark tests with @pytest.mark.simbind to make it run in separate process.
import pytest, pytest_simbind

from model import Model


@pytest_simbind.fixture
def model():
    return Model()


@pytest.mark.simbind
def test_something(model: Model):
    ...

Installation

To install pytest-simbind run:

$ pip install pytest-simbind

Requirements

You will need Python 3.10+ to run plugin. Additionally, plugin inherits some requirements from Simbind generated objects: while you can test your Mock model under any operational system, SiL model requires Linux! To learn more about Mock and SiL packages structure and usage, refer to Simbind Wiki.

Using API

pytest-simbind provides asynchronous API to:

  • dynamically select and run tests
  • collect Simbind model's data, test logs and fail reports.

Here is basic example on how to use API:

from pytest_simbind import SimbindCollector, dto as simbind_dto


def classifier(test_case: simbind_dto.TestCaseInfoDto) -> int | str | None:
    return test_case.node_id  # to select all the tests


collector = SimbindCollector(path_to_tests_root, classifier)

async for msg in collector.start():
    ...

The SimbindCollector requires path to the root directory of the tests and classifier callback function. This function is invoked for each discovered test. The return value of the classifier will be used as an id to tag the collected data from the test. If classifier returns None, test will be deselected from the execution run.

We encourage you to explore dto structures to better understand how to interact with the plugin. TestCaseInfoDto and TestUpdateDto could be a good start!

Simtest can be also used as an example and source of code snippets on how to interact with the plugin's API!

About

Pytest plugin to test Simbind generated models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages