Skip to content

Comments

Add settings callback support#90

Merged
radiac merged 2 commits intoradiac:mainfrom
SmileyChris:feature-settings-callbacks
Feb 14, 2026
Merged

Add settings callback support#90
radiac merged 2 commits intoradiac:mainfrom
SmileyChris:feature-settings-callbacks

Conversation

@SmileyChris
Copy link
Contributor

Summary

  • Allow using callbacks to modify default settings rather than replacing them
  • If a setting value is callable and the setting already exists in nanodjango's defaults, call it with the current value and use the return value
  • Add run_app_code test helper for creating and running temporary nanodjango apps

Example:

app = Django(
    MIDDLEWARE=lambda m: [MyPreMiddleware] + m + [MyPostMiddleware],
    INSTALLED_APPS=lambda apps: [a for a in apps if "admin" not in a],
)

Closes #74

Test plan

  • Test callback modifies MIDDLEWARE
  • Test callback filters INSTALLED_APPS
  • Test literal callable for new settings (like WHITENOISE_ADD_HEADERS_FUNCTION) is kept as-is
  • Test non-callable values work normally

Allow using callbacks to modify default settings rather than replacing them.
If a setting value is callable and the setting already exists in nanodjango's
defaults, call it with the current value and use the return value.

Closes radiac#74
Helper function for tests that need to create and run temporary nanodjango
apps with specific settings or code.
@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.96%. Comparing base (e91c6e3) to head (ecfe69f).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
nanodjango/app.py 0.00% 2 Missing ⚠️
nanodjango/testing/utils.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #90      +/-   ##
==========================================
+ Coverage   47.79%   47.96%   +0.17%     
==========================================
  Files          26       26              
  Lines        1904     1916      +12     
==========================================
+ Hits          910      919       +9     
- Misses        994      997       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@radiac radiac merged commit 28175e1 into radiac:main Feb 14, 2026
5 checks passed
@brianhelba
Copy link

@radiac This is a very helpful feature. I've been waiting in anticipation for it.

Could you create a new v0.14 release to make this easily usable downstream?

@radiac
Copy link
Owner

radiac commented Feb 16, 2026

I was just finishing adding another feature - 0.14 is up now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Released

Development

Successfully merging this pull request may close these issues.

Add settings callback support

3 participants