We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c0c768f commit 5af5eacCopy full SHA for 5af5eac
1 file changed
tests/test_feature_flags.py
@@ -32,3 +32,17 @@ def test_set_bad_setting():
32
pass
33
with pytest.raises(AttributeError):
34
lt.FEATURE_FLAGS.bogus_name = True
35
+
36
37
+@pytest.mark.parametrize("value", [True, False])
38
+def test_set_temporarily_with_exception(value):
39
+ """Test that flags are reset even if an exception occurs inside the block."""
40
+ value_before = lt.FEATURE_FLAGS.validate_properties_on_set
41
42
+ with pytest.raises(RuntimeError, match="Simulated crash"):
43
+ with lt.FEATURE_FLAGS.set_temporarily(validate_properties_on_set=value):
44
+ assert lt.FEATURE_FLAGS.validate_properties_on_set == value
45
+ raise RuntimeError("Simulated crash")
46
47
+ # The flag should be restored despite the exception
48
+ assert lt.FEATURE_FLAGS.validate_properties_on_set == value_before
0 commit comments