dls-controls / pythonSoftIOC

Embed an EPICS IOC in a Python process
Apache License 2.0
32 stars 7 forks source link

Allow users to reset the list of created records #56

Closed AlexanderWells-diamond closed 1 year ago

AlexanderWells-diamond commented 2 years ago

epicsdbbuilder exports the method ResetRecords(), documentation here, which allows the known list of records to be forgotten.

PythonSoftIOC maintains its own dictionary of records in RecordLookup, which appears to offer the same protections are epicsdbbuilder but offers no reset mechanism.

The situation I'm in is that I'm trying to test my record creation (note: not actually starting the IOC, just testing the creation). An epicsdbbuilder error about duplicat records is encountered first, but calling ResetRecords() allows me to work around that, within the published API. However I have no (sensible) way to reset the dictionary that PythonSoftIOC maintains. This would force me to create a multi-process test framework, which in quick tests is 2x-3x slower than running in a single process.

AlexanderWells-diamond commented 2 years ago

I seem to be able to do what I want by using these two lines in the teardown of each of my tests:

from softioc.device_core import RecordLookup
RecordLookup._RecordDirectory.clear()