Skip to content

Commit 5801b6f

Browse files
docs: update CHANGELOG for fixes and improvements in Django/pytest integration
- Added a new entry in `CHANGELOG.md` detailing the fix for the apparent infinite hang during pytest/CI due to incorrect settings import. - Updated `pytest.ini` to set `log_cli` to false by default to prevent logging issues during CI. - Enhanced logging in `api/models.py` to provide clearer visibility during model imports. - Removed the unnecessary appending of `coverage` to `INSTALLED_APPS` in `api/settings.py`. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e10f049 commit 5801b6f

6 files changed

Lines changed: 22 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ All contributors (including maintainers) should update `CHANGELOG.md` when creat
6464

6565
## [Unreleased]
6666

67+
### Fixed
68+
69+
- **Pytest / CI apparent infinite hang after settings**: [`api/test/tests/conftest.py`](api/test/tests/conftest.py) imports **`from django.conf import settings`** instead of **`from api import settings`**, so the full **`api.settings`** module is not run during conftest import (avoids bad interaction with pytest-django startup and **`log_cli`**). [`api/settings.py`](api/settings.py) no longer appends **`coverage`** to **`INSTALLED_APPS`** (the **`coverage`** PyPI package is not a Django application). [`pytest.ini`](pytest.ini) defaults **`log_cli=false`**; use **`pytest -o log_cli=true`** when you want live logs.
70+
6771
### CI
6872

6973
- **Static files workflow**: [`.github/workflows/static-files.yml`](.github/workflows/static-files.yml) sets **`ENV=collect_static`** in the job environment (Django collect-static path in **`api/settings.py`**); it is no longer read from the GitHub Variable **`ENV`**.
@@ -80,7 +84,7 @@ All contributors (including maintainers) should update `CHANGELOG.md` when creat
8084

8185
### Improved
8286

83-
- **Django / pytest startup visibility**: [`api/utils/utils.py`](api/utils/utils.py) **`print_django`** uses **`flush=True`**. [`api/settings.py`](api/settings.py) logs that **`django.setup()`** follows settings. [`api/urls.py`](api/urls.py) logs start/end of URLconf import; [`api/apps.py`](api/apps.py) **`ApiConfig.ready()`** logs when the app registry finishes the **`api`** app. [`api/test/tests/conftest.py`](api/test/tests/conftest.py) keeps **`[pytest]`** session/collection progress so long phases after settings do not look like a hang.
87+
- **Django / pytest startup visibility**: [`api/utils/utils.py`](api/utils/utils.py) **`print_django`** uses **`flush=True`**. [`api/settings.py`](api/settings.py) logs that **`django.setup()`** follows settings. [`api/models.py`](api/models.py) logs before/after the **`api`** model import chain (often the long gap before **`api.urls`**). [`api/urls.py`](api/urls.py) logs start/end of URLconf import; [`api/apps.py`](api/apps.py) **`ApiConfig.ready()`** logs when the **`api`** app **`ready()`** runs. [`api/test/tests/conftest.py`](api/test/tests/conftest.py) keeps **`[pytest]`** session/collection progress.
8488

8589
### Changed
8690

api/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import os
2+
import sys
3+
4+
if "pytest" in sys.argv[0] or os.environ.get("ENV") == "ci_test":
5+
print(
6+
"[Django] api.models: importing SpotifyArtist / SpotifyLibTrack / User (deep trees; can be slow)...",
7+
flush=True,
8+
)
9+
110
from api.model.spotify_resource.children.artist.SpotifyArtist import SpotifyArtist
211
from api.model.spotify_resource.children.track.SpotifyLibTrack import SpotifyLibTrack
312
from api.model.user.User import User
413

14+
if "pytest" in sys.argv[0] or os.environ.get("ENV") == "ci_test":
15+
print("[Django] api.models: core model imports finished.", flush=True)
16+
517
__all__ = ["SpotifyArtist", "SpotifyLibTrack", "User"]

api/settings.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Standard library imports
22
import datetime
3-
import importlib.util
43
import os
54
import sys
65
from pathlib import Path
@@ -539,9 +538,6 @@ def setup_installed_apps_and_caches():
539538
"api",
540539
]
541540

542-
if "pytest" in sys.argv[0] and importlib.util.find_spec("coverage") is not None:
543-
INSTALLED_APPS.append("coverage")
544-
545541
if APP_IS_EXPOSED:
546542
INSTALLED_APPS.append("rest_framework_simplejwt")
547543

api/test/tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
import pytest
1010
from _pytest.main import Session
11+
from django.conf import settings
1112
from django.test import override_settings
1213

13-
from api import settings
14-
1514
E2E_REACHABILITY_TIMEOUT_SEC = 5
1615

1716

pyrightconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"pythonVersion": "3.14",
33
"typeCheckingMode": "basic",
44
"reportMissingImports": "warning",
5+
"reportMissingModuleSource": false,
56
"reportMissingTypeStubs": false,
67
"pythonPlatform": "Darwin",
78
"executionEnvironments": [

pytest.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
DJANGO_SETTINGS_MODULE=api.settings
33
# Live logs at DEBUG swamp the terminal and look “hung”; use INFO by default.
44
# For deep debugging: pytest -o log_cli_level=DEBUG
5-
log_cli = true
5+
# Live CLI logging can interact badly with Django/pytest startup ordering in CI (apparent "hang" with no output).
6+
# Enable locally when needed: pytest -o log_cli=true -o log_cli_level=INFO
7+
log_cli = false
68
log_cli_level = INFO
79
filterwarnings =
810
ignore:unclosed file:ResourceWarning

0 commit comments

Comments
 (0)