Django-React-Redux-Boilerplate
Django-React-Redux-Boilerplate copied to clipboard
Running Tests with Pytest
Describe the bug
Django errors out with django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before access ing settings. when running pytest.
To Reproduce Steps to reproduce the behavior:
- install project
- navigate to {PROJECT_DIRECTORY}/backend
- run
python -m pytest
Expected behavior Pytest to pass out of the box
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Windows
- Browser: N/A
- Version: Latest
Suggested Fix
import os
import django
if not settings.configured:
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings'
django.setup()
could be added to backend/accounts/tests.py
Doesn't have to be included, just nice for people in the Pytest cult like me.
Ok, Thanks for the suggested fix. Will review and provide the feedback. ASAP
@mexicantexan Hey, check out the updated config for pytest. It's resolved.