diff --git a/pytest_django_test/compat.py b/pytest_django_test/compat.py index c6f5e0b94..0c9ce91f1 100644 --- a/pytest_django_test/compat.py +++ b/pytest_django_test/compat.py @@ -1,13 +1,4 @@ try: - from urllib2 import urlopen, HTTPError # noqa + from urllib2 import urlopen, HTTPError except ImportError: - from urllib.request import urlopen, HTTPError # noqa - -# Django 1.10 removes patterns, instead it is just a list -try: - from django.conf.urls import patterns -except ImportError: - - def patterns(prefix, *urls): - assert prefix == "" - return urls + from urllib.request import urlopen, HTTPError # noqa: F401 diff --git a/pytest_django_test/urls.py b/pytest_django_test/urls.py index e64494b1b..e96a371df 100644 --- a/pytest_django_test/urls.py +++ b/pytest_django_test/urls.py @@ -1,10 +1,8 @@ from django.conf.urls import url from .app import views -from .compat import patterns -urlpatterns = patterns( - "", +urlpatterns = [ url(r"^item_count/$", views.item_count), url(r"^admin-required/$", views.admin_required_view), -) +] diff --git a/pytest_django_test/urls_overridden.py b/pytest_django_test/urls_overridden.py index ceb34afe4..eca54e663 100644 --- a/pytest_django_test/urls_overridden.py +++ b/pytest_django_test/urls_overridden.py @@ -1,8 +1,6 @@ from django.conf.urls import url from django.http import HttpResponse -from .compat import patterns - -urlpatterns = patterns( - "", url(r"^overridden_url/$", lambda r: HttpResponse("Overridden urlconf works!")) -) +urlpatterns = [ + url(r"^overridden_url/$", lambda r: HttpResponse("Overridden urlconf works!")) +] diff --git a/tests/test_django_configurations.py b/tests/test_django_configurations.py index 5928a6e04..cdb8b4e1d 100644 --- a/tests/test_django_configurations.py +++ b/tests/test_django_configurations.py @@ -40,7 +40,7 @@ def test_settings(): """ ) result = testdir.runpytest_subprocess() - result.stdout.fnmatch_lines(["*1 passed*"]) + result.stdout.fnmatch_lines(["* 1 passed in*"]) assert result.ret == 0 @@ -68,7 +68,7 @@ def test_ds(): """ ) result = testdir.runpytest_subprocess() - result.stdout.fnmatch_lines(["*1 passed*"]) + result.stdout.fnmatch_lines(["* 1 passed in*"]) assert result.ret == 0 @@ -96,5 +96,5 @@ def test_ds(): """ ) result = testdir.runpytest_subprocess("--ds=tpkg.settings_opt", "--dc=MySettings") - result.stdout.fnmatch_lines(["*1 passed*"]) + result.stdout.fnmatch_lines(["* 1 passed in*"]) assert result.ret == 0 diff --git a/tests/test_django_settings_module.py b/tests/test_django_settings_module.py index 09b8427e8..a74bafeb6 100644 --- a/tests/test_django_settings_module.py +++ b/tests/test_django_settings_module.py @@ -138,7 +138,7 @@ def test_ds_after_user_conftest(testdir, monkeypatch): testdir.makepyfile(settings_after_conftest="SECRET_KEY='secret'") # testdir.makeconftest("import sys; print(sys.path)") result = testdir.runpytest_subprocess("-v") - result.stdout.fnmatch_lines(["*1 passed*"]) + result.stdout.fnmatch_lines(["* 1 passed in*"]) assert result.ret == 0 @@ -226,7 +226,7 @@ def test_user_count(): """ ) result = testdir.runpython(p) - result.stdout.fnmatch_lines(["*4 passed*"]) + result.stdout.fnmatch_lines(["* 4 passed in*"]) def test_settings_in_hook(testdir, monkeypatch): @@ -275,7 +275,7 @@ def test_settings(): """ ) result = testdir.runpytest_subprocess() - result.stdout.fnmatch_lines(["*1 passed*"]) + result.stdout.fnmatch_lines(["* 1 passed in*"]) assert result.ret == 0 diff --git a/tests/test_environment.py b/tests/test_environment.py index 4eb978024..64f030208 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -58,14 +58,10 @@ def test_invalid_template_variable(django_testdir): django_testdir.create_app_file( """ from django.conf.urls import url - from pytest_django_test.compat import patterns from tpkg.app import views - urlpatterns = patterns( - '', - url(r'invalid_template/', views.invalid_template), - ) + urlpatterns = [url(r'invalid_template/', views.invalid_template)] """, "urls.py", ) @@ -168,14 +164,10 @@ def test_invalid_template_variable_opt_in(django_testdir): django_testdir.create_app_file( """ from django.conf.urls import url - from pytest_django_test.compat import patterns from tpkg.app import views - urlpatterns = patterns( - '', - url(r'invalid_template/', views.invalid_template), - ) + urlpatterns = [url(r'invalid_template/', views.invalid_template)] """, "urls.py", ) diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 7309a36dd..07f401574 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -518,13 +518,9 @@ class MyCustomUser(AbstractUser): django_testdir.create_app_file( """ from django.conf.urls import url - from pytest_django_test.compat import patterns from tpkg.app import views - urlpatterns = patterns( - '', - url(r'admin-required/', views.admin_required_view), - ) + urlpatterns = [url(r'admin-required/', views.admin_required_view)] """, "urls.py", ) @@ -543,12 +539,12 @@ def admin_required_view(request): ) django_testdir.makepyfile( """ - from django.utils.encoding import force_text + from django.utils.encoding import force_str from tpkg.app.models import MyCustomUser def test_custom_user_model(admin_client): resp = admin_client.get('/admin-required/') - assert force_text(resp.content) == 'You are an admin' + assert force_str(resp.content) == 'You are an admin' """ ) @@ -578,7 +574,7 @@ class Migration(migrations.Migration): ('password', models.CharField(max_length=128, verbose_name='password')), ('last_login', models.DateTimeField(null=True, verbose_name='last login', blank=True)), ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), - ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, max_length=30, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.', 'invalid')], help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, verbose_name='username')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, max_length=30, validators=[django.core.validators.RegexValidator(r'^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.', 'invalid')], help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, verbose_name='username')), ('first_name', models.CharField(max_length=30, verbose_name='first name', blank=True)), ('last_name', models.CharField(max_length=30, verbose_name='last name', blank=True)), ('email', models.EmailField(max_length=254, verbose_name='email address', blank=True)), @@ -602,7 +598,7 @@ class Migration(migrations.Migration): ) result = django_testdir.runpytest_subprocess("-s") - result.stdout.fnmatch_lines(["*1 passed*"]) + result.stdout.fnmatch_lines(["* 1 passed in*"]) assert result.ret == 0 diff --git a/tests/test_initialization.py b/tests/test_initialization.py index 47680e942..33544bd26 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -54,7 +54,7 @@ def test_ds(): "conftest", "pytest_configure: conftest", "pytest_configure: plugin", - "*1 passed*", + "* 1 passed in*", ] ) assert result.ret == 0 diff --git a/tests/test_unittest.py b/tests/test_unittest.py index bf079cfee..15badf79b 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -392,7 +392,7 @@ def test_noop(self): result = django_testdir.runpytest_subprocess("-q", "-s") result.stdout.fnmatch_lines( - ["*FooBarTestCase.setUpClass*", "*test_noop*", "1 passed*"] + ["*FooBarTestCase.setUpClass*", "*test_noop*", "1 passed in*"] ) assert result.ret == 0 diff --git a/tests/test_urls.py b/tests/test_urls.py index f50996118..8067f1359 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -23,12 +23,11 @@ def test_urls_cache_is_cleared(testdir): testdir.makepyfile( myurls=""" from django.conf.urls import url - from pytest_django_test.compat import patterns def fake_view(request): pass - urlpatterns = patterns('', url(r'first/$', fake_view, name='first')) + urlpatterns = [url(r'first/$', fake_view, name='first')] """ ) @@ -60,24 +59,22 @@ def test_urls_cache_is_cleared_and_new_urls_can_be_assigned(testdir): testdir.makepyfile( myurls=""" from django.conf.urls import url - from pytest_django_test.compat import patterns def fake_view(request): pass - urlpatterns = patterns('', url(r'first/$', fake_view, name='first')) + urlpatterns = [url(r'first/$', fake_view, name='first')] """ ) testdir.makepyfile( myurls2=""" from django.conf.urls import url - from pytest_django_test.compat import patterns def fake_view(request): pass - urlpatterns = patterns('', url(r'second/$', fake_view, name='second')) + urlpatterns = [url(r'second/$', fake_view, name='second')] """ ) diff --git a/tox.ini b/tox.ini index d70c2583e..8c4964fb6 100644 --- a/tox.ini +++ b/tox.ini @@ -44,7 +44,7 @@ setenv = coverage: COVERAGE_FILE={toxinidir}/.coverage coverage: PYTESTDJANGO_COVERAGE_SRC={toxinidir}/ -passenv = PYTEST_ADDOPTS +passenv = PYTEST_ADDOPTS TERM usedevelop = True commands = coverage: coverage erase