Skip to content

Commit 5af5eac

Browse files
committed
o
Test `set_temporarily` recovers from exceptions. Thanks @bprobert97 for this test.
1 parent c0c768f commit 5af5eac

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_feature_flags.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ def test_set_bad_setting():
3232
pass
3333
with pytest.raises(AttributeError):
3434
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

Comments
 (0)