Django-React-Redux-Boilerplate icon indicating copy to clipboard operation
Django-React-Redux-Boilerplate copied to clipboard

Running Tests with Pytest

Open mexicantexan opened this issue 3 years ago • 2 comments

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:

  1. install project
  2. navigate to {PROJECT_DIRECTORY}/backend
  3. 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

mexicantexan avatar Jul 26 '22 18:07 mexicantexan

Doesn't have to be included, just nice for people in the Pytest cult like me.

mexicantexan avatar Jul 26 '22 18:07 mexicantexan

Ok, Thanks for the suggested fix. Will review and provide the feedback. ASAP

faisalnazik avatar Aug 01 '22 10:08 faisalnazik

@mexicantexan Hey, check out the updated config for pytest. It's resolved.

faisalnazik avatar Dec 19 '22 12:12 faisalnazik