mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Make test context managers more reliable
Sometimes, when a test using one of the set_config[_values] context managers failed or raised an exception it would cause the context to not be able to revert its config changes, resulting in a 'spooky action at a distance' where random tests would start to fail for non-obvious reasons.
This commit is contained in:
@@ -141,8 +141,10 @@ def pytest_generate_tests(metafunc):
|
||||
def set_config(app, name, value):
|
||||
old_val = app.config.get(name)
|
||||
app.config[name] = value
|
||||
yield
|
||||
app.config[name] = old_val
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
app.config[name] = old_val
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -153,7 +155,8 @@ def set_config_values(app, dict):
|
||||
old_values[key] = app.config.get(key)
|
||||
app.config[key] = dict[key]
|
||||
|
||||
yield
|
||||
|
||||
for key in dict:
|
||||
app.config[key] = old_values[key]
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
for key in dict:
|
||||
app.config[key] = old_values[key]
|
||||
|
||||
Reference in New Issue
Block a user