11"""All pytest-django fixtures"""
22
3- from __future__ import with_statement
43
54import os
6- import warnings
75from contextlib import contextmanager
86from functools import partial
97
@@ -91,7 +89,7 @@ def django_db_setup(
9189 django_db_modify_db_settings ,
9290):
9391 """Top level fixture to ensure test databases are available"""
94- from . compat import setup_databases , teardown_databases
92+ from django . test . utils import setup_databases , teardown_databases
9593
9694 setup_databases_args = {}
9795
@@ -164,7 +162,7 @@ def _disable_native_migrations():
164162 class MigrateSilentCommand (migrate .Command ):
165163 def handle (self , * args , ** kwargs ):
166164 kwargs ["verbosity" ] = 0
167- return super (MigrateSilentCommand , self ).handle (* args , ** kwargs )
165+ return super ().handle (* args , ** kwargs )
168166
169167 migrate .Command = MigrateSilentCommand
170168
@@ -320,7 +318,7 @@ def rf():
320318 return RequestFactory ()
321319
322320
323- class SettingsWrapper ( object ) :
321+ class SettingsWrapper :
324322 _to_restore = []
325323
326324 def __delattr__ (self , attr ):
@@ -370,8 +368,8 @@ def live_server(request):
370368 The address the server is started from is taken from the
371369 --liveserver command line option or if this is not provided from
372370 the DJANGO_LIVE_TEST_SERVER_ADDRESS environment variable. If
373- neither is provided ``localhost:8081,8100-8200 `` is used. See the
374- Django documentation for its full syntax.
371+ neither is provided ``localhost`` is used. See the Django
372+ documentation for its full syntax.
375373
376374 NOTE: If the live server needs database access to handle a request
377375 your test will have to request database access. Furthermore
@@ -385,27 +383,9 @@ def live_server(request):
385383 """
386384 skip_if_no_django ()
387385
388- import django
389-
390386 addr = request .config .getvalue ("liveserver" ) or os .getenv (
391387 "DJANGO_LIVE_TEST_SERVER_ADDRESS"
392- )
393-
394- if addr and ":" in addr :
395- if django .VERSION >= (1 , 11 ):
396- ports = addr .split (":" )[1 ]
397- if "-" in ports or "," in ports :
398- warnings .warn (
399- "Specifying multiple live server ports is not supported "
400- "in Django 1.11. This will be an error in a future "
401- "pytest-django release."
402- )
403-
404- if not addr :
405- if django .VERSION < (1 , 11 ):
406- addr = "localhost:8081,8100-8200"
407- else :
408- addr = "localhost"
388+ ) or "localhost"
409389
410390 server = live_server_helper .LiveServer (addr )
411391 request .addfinalizer (server .stop )
@@ -458,14 +438,14 @@ def _assert_num_queries(config, num, exact=True, connection=None, info=None):
458438 num ,
459439 "" if exact else "or less " ,
460440 "but {} done" .format (
461- num_performed == 1 and "1 was" or "%d were" % (num_performed , )
441+ num_performed == 1 and "1 was" or "{} were" . format (num_performed )
462442 ),
463443 )
464444 if info :
465445 msg += "\n {}" .format (info )
466446 if verbose :
467447 sqls = (q ["sql" ] for q in context .captured_queries )
468- msg += "\n \n Queries:\n ========\n \n %s" % "\n \n " .join (sqls )
448+ msg += "\n \n Queries:\n ========\n \n " + "\n \n " .join (sqls )
469449 else :
470450 msg += " (add -v option to show queries)"
471451 pytest .fail (msg )
0 commit comments