Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK

Tags:

django

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.

like image 584
78387 Avatar asked Aug 15 '26 03:08

78387


2 Answers

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)

like image 121
El farouk Avatar answered Aug 17 '26 19:08

El farouk


I resolved the issue by installing the pytest-django library in my environment

like image 21
Jay Kuehn Avatar answered Aug 17 '26 21:08

Jay Kuehn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!