Skip to content

Commit

Permalink
allow to execute one test multiple times with different parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Apr 26, 2024
1 parent 608fd0a commit 327d5e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,25 @@ If you wish to use the `healthcheck` [management command](#management-command),

The default "health" endpoint will test a simple `SELECT 1` query on the database. Additional checks can be enabled in your Django settings.

Use the `ALIVE_CHECKS` setting to configure the checks to include. It is a dictionary with the path to a Python function as a key and any keyword arguments to pass to that function as a value. A full example:
Use the `ALIVE_CHECKS` setting to configure the checks to include. It is a list of tuples with the path to a Python function as a first argiment and dict of keyword arguments to pass to that function as a second argument. A full example:

```python
ALIVE_CHECKS = {
"django_alive.checks.check_database": {},
"django_alive.checks.check_staticfile": {
ALIVE_CHECKS = [
("django_alive.checks.check_database", {}),
("django_alive.checks.check_staticfile", {
"filename": "img/favicon.ico",
},
"django_alive.checks.check_cache": {
}),
("django_alive.checks.check_cache", {
"cache": "session",
"key": "test123",
},
"django_alive.checks.check_migrations": {},
}
}),
("django_alive.checks.check_migrations", {}),
]
```

**⚠️ Warning: DCanged in version 1.3.0 ⚠️⚠️**

**NOTE:** Old settings with `ALIVE_CHECKS` as dict was deprecated in favor of a list of tuples.

```
Expand Down
13 changes: 12 additions & 1 deletion django_alive/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from django.conf import settings
from django.utils.module_loading import import_string

Expand All @@ -17,7 +18,17 @@
def perform_healthchecks():
# typing: () -> (bool, List[str])
errors = []
for func, kwargs in ALIVE_CHECKS.items():
if isinstance(ALIVE_CHECKS, dict):
# Deprecated dict format
warnings.warn(
"ALIVE_CHECKS should be a list of tuples, not a dict. "
"Please update your settings.",
DeprecationWarning,
)
checks = ALIVE_CHECKS.items()
else:
checks = ALIVE_CHECKS
for func, kwargs in checks:
try:
import_string(func)(**kwargs)
except HealthcheckFailure as e:
Expand Down

0 comments on commit 327d5e5

Please sign in to comment.