-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to get a list of all settings in a module
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,26 @@ | ||
"""Helper methods for testing. | ||
Includes a plugin for Pytest. | ||
""" | ||
Includes a plugin for Pytest. | ||
""" | ||
|
||
from types import ModuleType | ||
|
||
from ..conf.loaders import settings_iterator | ||
|
||
|
||
def settings_in_module( | ||
*modules: ModuleType, | ||
exclude: list[str] = ("INCLUDE",), | ||
): | ||
"""Generate a list of settings defined in a module (or modules). | ||
Used for ensuring that a second settings module only contains specified settings. | ||
""" | ||
settings = set() | ||
|
||
for mod in modules: | ||
settings.update( | ||
name for name, _ in settings_iterator(mod) if name not in exclude | ||
) | ||
|
||
return settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from pyapp import testing | ||
|
||
|
||
def test_settings_in_module(): | ||
from pyapp.conf import base_settings | ||
|
||
actual = testing.settings_in_module(base_settings) | ||
|
||
assert actual == { | ||
"DEBUG", | ||
"LOG_LOGGERS", | ||
"LOG_HANDLERS", | ||
"LOGGING", | ||
"CHECK_LOCATIONS", | ||
"FEATURE_FLAGS", | ||
"FEATURE_FLAG_PREFIX", | ||
} |