Description
Describe the bug
django-select2 uses django-appconf, which has a problem sometimes appearing when using tests with @override_settings()
that causes some tests not to be able to see the settings.
The fix is outlined here: consists of making sure that in Select2AppConfig.ready()
, we import the conf module.
Exception & Traceback
Traceback (most recent call last):
File "/home/joachim/other-src/select2_issue/bugshowcase/tests/tests.py", line 14, in test_2
assert settings.SELECT2_THEME
File "/home/joachim/.envs/select2_issue/lib/python3.10/site-packages/django/conf/__init__.py", line 83, in __getattr__
val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'SELECT2_THEME'
Code Snippet
https://github.com/ewjoachim/django_select2_showcase_203
To Reproduce
Steps to reproduce the behavior:
- Clone https://github.com/ewjoachim/django_select2_showcase_203.git
- Create a venv and activate it
pip install -r requirements.txt
python manage.py test bugshowcase/tests
The 1st test is written so that the 1st time django_select2's configuration is loaded is during a @override_settings
context. Because of this, when the 1st test ends, the settings disappear. The 2nd test shows this by trying to read the settings.
The bug is especially annoying as is depends on test order, import order, and many other factors.
Adding an import to django_select2.conf
within any AppConfig.ready()
solves it.
Expected behavior
no error