Skip to content

Parameter values shared across Python class instances #313

@Mat198

Description

@Mat198

I’m trying to create tests to verify the interaction of my software with the generate_parameter_library. I want to save the parameters to a file when they are updated in both Python and C++. The testes for the C++ version worked correctly, but in Python, I noticed an odd behaviour. The parameter values are shared across multiple instances. This resulted in the tests failing due to an inconsistent initial value. I expected a reset to parameter values when a new instance is created.

Looking at the generated code, I noticed the Param class doesn’t have an __init__(self) function and declares the parameters directly in the class body. This causes the parameters to be shared between instances. Is this the desired behaviour?

Adding the __init__(self) function and selfto the variables solved this. As a quick fix, I reloaded the entire module between each test.

If this is not intended, I can provide a pull request to solve this issue.

Auto generated code:
Image

Expected generated code:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions