Skip to content

Commit 6700f10

Browse files
blueyedpelme
authored andcommitted
minor: formatting / line-length fixes (#363)
* minor: formatting / line-length fixes * fixup! minor: formatting / line-length fixes * fixup! fixup! minor: formatting / line-length fixes
1 parent 53bb1ab commit 6700f10

File tree

4 files changed

+44
-35
lines changed

4 files changed

+44
-35
lines changed

docs/helpers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ also directly concatenate a string to form a URL: ``live_server +
205205
``settings``
206206
~~~~~~~~~~~~
207207

208-
This fixture will provide a handle on the django settings module, and
208+
This fixture will provide a handle on the Django settings module, and
209209
automatically revert any changes made to the settings (modifications, additions
210210
and deletions).
211211

pytest_django/fixtures.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def django_db_use_migrations(request):
5858

5959
@pytest.fixture(scope='session')
6060
def django_db_keepdb(request):
61-
return request.config.getvalue('reuse_db') and not request.config.getvalue('create_db')
61+
return (request.config.getvalue('reuse_db') and not
62+
request.config.getvalue('create_db'))
6263

6364

6465
@pytest.fixture(scope='session')
@@ -97,7 +98,8 @@ def django_db_setup(
9798

9899
def teardown_database():
99100
with django_db_blocker:
100-
(DiscoverRunner(verbosity=pytest.config.option.verbose, interactive=False)
101+
(DiscoverRunner(verbosity=pytest.config.option.verbose,
102+
interactive=False)
101103
.teardown_databases(db_cfg))
102104

103105
if not django_db_keepdb:

pytest_django/plugin.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
from .fixtures import settings # noqa
3333
from .fixtures import transactional_db # noqa
3434

35-
from .lazy_django import django_settings_is_configured, skip_if_no_django
35+
from .lazy_django import (django_settings_is_configured,
36+
get_django_version, skip_if_no_django)
3637

3738

3839
SETTINGS_MODULE_ENV = 'DJANGO_SETTINGS_MODULE'
@@ -140,7 +141,7 @@ def _setup_django():
140141

141142
import django.conf
142143

143-
# Avoid trying to force-load Django when settings is not properly configured
144+
# Avoid force-loading Django when settings are not properly configured.
144145
if not django.conf.settings.configured:
145146
return
146147

@@ -203,7 +204,6 @@ def pytest_load_initial_conftests(early_config, parser, args):
203204
os.environ[INVALID_TEMPLATE_VARS_ENV] = 'true'
204205

205206
# Configure DJANGO_SETTINGS_MODULE
206-
207207
if options.ds:
208208
ds_source = 'command line option'
209209
ds = options.ds
@@ -218,7 +218,8 @@ def pytest_load_initial_conftests(early_config, parser, args):
218218
ds_source = None
219219

220220
if ds:
221-
early_config._dsm_report_header = 'django settings: %s (from %s)' % (ds, ds_source)
221+
early_config._dsm_report_header = 'Django settings: %s (from %s)' % (
222+
ds, ds_source)
222223
else:
223224
early_config._dsm_report_header = None
224225

@@ -237,12 +238,12 @@ def pytest_load_initial_conftests(early_config, parser, args):
237238
import configurations.importer
238239
configurations.importer.install()
239240

240-
# Forcefully load django settings, throws ImportError or
241+
# Forcefully load Django settings, throws ImportError or
241242
# ImproperlyConfigured if settings cannot be loaded.
242-
from django.conf import settings # noqa
243+
from django.conf import settings as dj_settings
243244

244245
with _handle_import_error(_django_project_scan_outcome):
245-
settings.DATABASES
246+
dj_settings.DATABASES
246247

247248
_setup_django()
248249

@@ -266,7 +267,8 @@ def _method_is_defined_at_leaf(cls, method_name):
266267
if hasattr(base_cls, method_name):
267268
super_method = getattr(base_cls, method_name)
268269

269-
assert super_method is not None, '%s could not be found in base class' % method_name
270+
assert super_method is not None, (
271+
'%s could not be found in base class' % method_name)
270272

271273
return getattr(cls, method_name).__func__ is not super_method.__func__
272274

@@ -332,9 +334,10 @@ def django_test_environment(request):
332334
"""
333335
if django_settings_is_configured():
334336
_setup_django()
335-
from django.conf import settings # noqa
336-
from django.test.utils import setup_test_environment, teardown_test_environment
337-
settings.DEBUG = False
337+
from django.conf import settings as dj_settings
338+
from django.test.utils import (setup_test_environment,
339+
teardown_test_environment)
340+
dj_settings.DEBUG = False
338341
setup_test_environment()
339342
request.addfinalizer(teardown_test_environment)
340343

@@ -348,10 +351,11 @@ def django_db_blocker():
348351
special database handling.
349352
350353
The object is a context manager and provides the methods
351-
.enable_database_access()/.disable_database_access() and .restore_database_access() to
352-
temporarily enable database access.
354+
.enable_database_access()/.disable_database_access() and
355+
.restore_database_access() to temporarily enable database access.
353356
354-
This is an advanced feature that is meant to be used to implement database fixtures.
357+
This is an advanced feature that is meant to be used to implement database
358+
fixtures.
355359
"""
356360
if not django_settings_is_configured():
357361
return None
@@ -480,22 +484,24 @@ def __mod__(self, var):
480484
"""Handle TEMPLATE_STRING_IF_INVALID % var."""
481485
template = self._get_template()
482486
if template:
483-
msg = "Undefined template variable '%s' in '%s'" % (var, template.name)
487+
msg = "Undefined template variable '%s' in '%s'" % (
488+
var, template.name)
484489
else:
485490
msg = "Undefined template variable '%s'" % var
486491
if self.fail:
487492
pytest.fail(msg, pytrace=False)
488493
else:
489494
return msg
490-
if os.environ.get(INVALID_TEMPLATE_VARS_ENV, 'false') == 'true':
491-
if django_settings_is_configured():
492-
import django
493-
from django.conf import settings # noqa
494495

495-
if django.VERSION >= (1, 8) and settings.TEMPLATES:
496-
settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] = InvalidVarException()
497-
else:
498-
settings.TEMPLATE_STRING_IF_INVALID = InvalidVarException()
496+
if (os.environ.get(INVALID_TEMPLATE_VARS_ENV, 'false') == 'true' and
497+
django_settings_is_configured()):
498+
from django.conf import settings as dj_settings
499+
500+
if get_django_version() >= (1, 8) and dj_settings.TEMPLATES:
501+
dj_settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] = (
502+
InvalidVarException())
503+
else:
504+
dj_settings.TEMPLATE_STRING_IF_INVALID = InvalidVarException()
499505

500506

501507
@pytest.fixture(autouse=True)
@@ -505,13 +511,12 @@ def _template_string_if_invalid_marker(request):
505511
marker = request.keywords.get('ignore_template_errors', None)
506512
if os.environ.get(INVALID_TEMPLATE_VARS_ENV, 'false') == 'true':
507513
if marker and django_settings_is_configured():
508-
import django
509-
from django.conf import settings # noqa
514+
from django.conf import settings as dj_settings
510515

511-
if django.VERSION >= (1, 8) and settings.TEMPLATES:
512-
settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'].fail = False
516+
if get_django_version() >= (1, 8) and dj_settings.TEMPLATES:
517+
dj_settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'].fail = False
513518
else:
514-
settings.TEMPLATE_STRING_IF_INVALID.fail = False
519+
dj_settings.TEMPLATE_STRING_IF_INVALID.fail = False
515520

516521
# ############### Helper Functions ################
517522

@@ -535,7 +540,7 @@ def _dj_db_wrapper(self):
535540
from django.db.backends import BaseDatabaseWrapper
536541

537542
# The first time the _dj_db_wrapper is accessed, we will save a
538-
# reference to the real implementation
543+
# reference to the real implementation.
539544
if self._real_ensure_connection is None:
540545
self._real_ensure_connection = BaseDatabaseWrapper.ensure_connection
541546

tests/test_django_settings_module.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def test_ds():
3535
""")
3636
result = testdir.runpytest_subprocess()
3737
assert result.parseoutcomes()['passed'] == 1
38-
result.stdout.fnmatch_lines(['django settings: tpkg.settings_ini (from ini file)*'])
38+
result.stdout.fnmatch_lines(['Django settings: tpkg.settings_ini '
39+
'(from ini file)*'])
3940
assert result.ret == 0
4041

4142

@@ -51,7 +52,7 @@ def test_settings():
5152
assert os.environ['DJANGO_SETTINGS_MODULE'] == 'tpkg.settings_env'
5253
""")
5354
result = testdir.runpytest_subprocess()
54-
result.stdout.fnmatch_lines(['django settings: tpkg.settings_env (from '
55+
result.stdout.fnmatch_lines(['Django settings: tpkg.settings_env (from '
5556
'environment variable)*'])
5657
assert result.parseoutcomes()['passed'] == 1
5758

@@ -72,7 +73,8 @@ def test_ds():
7273
assert os.environ['DJANGO_SETTINGS_MODULE'] == 'tpkg.settings_opt'
7374
""")
7475
result = testdir.runpytest_subprocess('--ds=tpkg.settings_opt')
75-
result.stdout.fnmatch_lines(['django settings: tpkg.settings_opt (from command line option)'])
76+
result.stdout.fnmatch_lines(['Django settings: tpkg.settings_opt '
77+
'(from command line option)'])
7678
assert result.parseoutcomes()['passed'] == 1
7779

7880

0 commit comments

Comments
 (0)