File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments