How to import whole python file and not break F403 flake8 rule?

638 Views Asked by At

Imports like this:

from .file import *

are "anti-patterns". How can I import one python file into another, without breaking flake8 F430 rule? I have settings.py in the Django project that I want to "overwrite" in test_settings.py like this,

from settings import *

# make tests faster
DATABASES['default'] = {'ENGINE': 'django.db.backends.sqlite3'}

to test with in-memory database, and I cant figure out how to do it without breaking the rule.

1

There are 1 best solutions below

0
On

According to authors of the book "Two Scoops of Django 3.x" this is actually an exception when they advocate using

import *

the singular case of Django setting modules we want to override all the namespace

in order to allow usage of multiple settings files. Therefore in this situation, the best solution is to exclude test_settings.py from the flake8 scan, in the flake8 configuration file.