Why do I have the following problem when running tests? Tried everything already, nothing seems to work:
django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Everything is working, but the testing.
you didn't provide the full picture of the project structure so I am going to pin point what would usually cause this problem :
1. install pytest-django
$ pipenv install --dev pytest-django
2. create a file to define the settings module, and name it pytest.ini
[pytest] DJANGO_SETTINGS_MODULE=storefront.settings
replace "storefront" with your root folder and make sure the spelling is right , also this file should be on the root directory along side with the manage.py file .
3. in the terminal type pytest , remember to execute this command in the root directory (the same place you $ python manage.py runserver)
I resolved the issue by installing the pytest-django library in my environment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With