Skip to content

Commit

Permalink
Run black on source
Browse files Browse the repository at this point in the history
Fixes flake8, where we use "binary operator after line breaks".

Closes #670.
  • Loading branch information
blueyed committed Oct 30, 2018
1 parent 22ebd0a commit 9804e61
Show file tree
Hide file tree
Showing 22 changed files with 1,413 additions and 1,042 deletions.
13 changes: 8 additions & 5 deletions pytest_django/compat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# This file cannot be imported from until Django sets up
try:
# Django 1.11
from django.test.utils import setup_databases, teardown_databases # noqa
from django.test.utils import setup_databases, teardown_databases # noqa: F401
except ImportError:
# In Django prior to 1.11, teardown_databases is only available as a method on DiscoverRunner
from django.test.runner import setup_databases, DiscoverRunner as _DiscoverRunner # noqa
from django.test.runner import ( # noqa: F401
setup_databases,
DiscoverRunner as _DiscoverRunner,
)

def teardown_databases(db_cfg, verbosity):
(_DiscoverRunner(verbosity=verbosity,
interactive=False)
.teardown_databases(db_cfg))
_DiscoverRunner(verbosity=verbosity, interactive=False).teardown_databases(
db_cfg
)
30 changes: 17 additions & 13 deletions pytest_django/db_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ def test_database_exists_from_previous_run(connection):

# When using a real SQLite backend (via TEST_NAME), check if the file
# exists, because it gets created automatically.
if connection.settings_dict['ENGINE'] == 'django.db.backends.sqlite3':
if connection.settings_dict["ENGINE"] == "django.db.backends.sqlite3":
if not os.path.exists(test_db_name):
return False

orig_db_name = connection.settings_dict['NAME']
connection.settings_dict['NAME'] = test_db_name
orig_db_name = connection.settings_dict["NAME"]
connection.settings_dict["NAME"] = test_db_name

# With SQLite memory databases the db never exists.
if connection.settings_dict['NAME'] == ':memory:':
if connection.settings_dict["NAME"] == ":memory:":
return False

try:
Expand All @@ -29,7 +29,7 @@ def test_database_exists_from_previous_run(connection):
return False
finally:
connection.close()
connection.settings_dict['NAME'] = orig_db_name
connection.settings_dict["NAME"] = orig_db_name


def _monkeypatch(obj, method_name, new_method):
Expand All @@ -43,8 +43,9 @@ def _monkeypatch(obj, method_name, new_method):
setattr(obj, method_name, wrapped_method)


def create_test_db_with_reuse(self, verbosity=1, autoclobber=False,
keepdb=False, serialize=False):
def create_test_db_with_reuse(
self, verbosity=1, autoclobber=False, keepdb=False, serialize=False
):
"""
This method is a monkey patched version of create_test_db that
will not actually create a new database, but just reuse the
Expand All @@ -53,14 +54,16 @@ def create_test_db_with_reuse(self, verbosity=1, autoclobber=False,
This is only used with Django < 1.8.
"""
test_database_name = self._get_test_db_name()
self.connection.settings_dict['NAME'] = test_database_name
self.connection.settings_dict["NAME"] = test_database_name

if verbosity >= 1:
test_db_repr = ''
test_db_repr = ""
if verbosity >= 2:
test_db_repr = " ('%s')" % test_database_name
print("Re-using existing test database for alias '%s'%s..." % (
self.connection.alias, test_db_repr))
print(
"Re-using existing test database for alias '%s'%s..."
% (self.connection.alias, test_db_repr)
)

return test_database_name

Expand All @@ -70,5 +73,6 @@ def monkey_patch_creation_for_db_reuse():

for connection in connections.all():
if test_database_exists_from_previous_run(connection):
_monkeypatch(connection.creation, 'create_test_db',
create_test_db_with_reuse)
_monkeypatch(
connection.creation, "create_test_db", create_test_db_with_reuse
)
2 changes: 1 addition & 1 deletion pytest_django/django_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def is_django_unittest(request_or_item):
"""Returns True if the request_or_item is a Django test case, otherwise False"""
from django.test import SimpleTestCase

cls = getattr(request_or_item, 'cls', None)
cls = getattr(request_or_item, "cls", None)

if cls is None:
return False
Expand Down
Loading

0 comments on commit 9804e61

Please sign in to comment.