Pioreactor / pioreactor

Hardware and software for accessible, extensible, and scalable bioreactors. Built on Raspberry Pi.
https://pioreactor.com
MIT License
101 stars 9 forks source link

simple utility to change and revert config changes for tests #479

Open CamDavidsonPilon opened 8 months ago

CamDavidsonPilon commented 8 months ago

From

def test_auto_ir_led_intensity() -> None:
    from pioreactor.config import config

    existing_intensity = config["od_config"]["ir_led_intensity"]

    config["od_config"]["ir_led_intensity"] = "auto"

    experiment = "test_auto_ir_led_intensity"

    with start_od_reading("REF", "90", interval=None, fake_data=True, experiment=experiment) as od:
        assert od.ir_led_intensity == 20.0

    config["od_config"]["ir_led_intensity"] = existing_intensity

to

def test_auto_ir_led_intensity() -> None:
    from pioreactor.config import config
    experiment = "test_auto_ir_led_intensity"

    with config.temp_update("od_config", "ir_led_intensity", "auto"):
      with start_od_reading("REF", "90", interval=None, fake_data=True, experiment=experiment) as od:
          assert od.ir_led_intensity == 20.0
CamDavidsonPilon commented 7 hours ago

Actually I would use this in prod to, ex temporarily "disable" dodging ODs in stirring.