class_docstr: Test the helper function for sequential API
class_docstr_tok: ["Test","the","helper","function","for","sequential","API"]
docstr: Verify that storage is reverted if workon fails
docstr_tok: ["Verify","that","storage","is","reverted","if","workon","fails"]
code: def test_workon_fail(self, monkeypatch):
      """Verify that storage is reverted if workon fails"""
  
      def foo(x):
          return [dict(name="result", type="objective", value=x * 2)]
  
      def build_fail(*args, **kwargs):
          raise RuntimeError("You shall not build!")
  
      monkeypatch.setattr(
          "orion.core.io.experiment_builder.build", build_fail
      )
  
      # Flush storage singleton
  
      with pytest.raises(RuntimeError) as exc:
          experiment = workon(
              foo,
              space={"x": "uniform(0, 10)"},
              max_trials=5,
              name="voici",
          )
  
      assert exc.match("You shall not build!")
  
      # Now test with a prior storage
      with OrionState(
          storage={
              "type": "legacy",
              "database": {"type": "EphemeralDB"},
          }
      ) as cfg:
          storage = cfg.storage
  
          with pytest.raises(RuntimeError) as exc:
              workon(
                  foo,
                  space={"x": "uniform(0, 10)"},
                  max_trials=5,
                  name="voici",
              )
  
          assert exc.match("You shall not build!")
  
imports: import copy
  import json
  from importlib import reload
  import pytest
  import orion.client
  import orion.client.cli
  import orion.core
  from orion.algo.random import Random
  from orion.client import get_experiment
  from orion.client.experiment import ExperimentClient
  from orion.core.io.database.ephemeraldb import EphemeralDB
  from orion.core.io.database.pickleddb import PickledDB
  from orion.core.utils.exceptions import BranchingEvent, NoConfigurationError, RaceCondition, UnsupportedOperation
  from orion.storage.base import setup_storage
  from orion.storage.legacy import Legacy
  from orion.testing import OrionState
label_desc: Use image node_id 4 for calling the TestWorkon obj's underlying member method code with example usage: obj.test_workon_fail(monkeypatch) and returns: list