From 39b1e13e0c6ff746434c3a981573563e004cf70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4ufl?= Date: Mon, 9 Oct 2017 10:26:55 +0200 Subject: [PATCH 1/2] Drop support for Django 1.7 --- .travis.yml | 2 -- README.rst | 2 +- docs/contributing.rst | 6 +++--- docs/helpers.rst | 2 +- docs/managing_python_path.rst | 2 +- pytest_django/compat.py | 7 +------ pytest_django/fixtures.py | 11 ++--------- pytest_django/plugin.py | 11 +++++------ tests/test_db_setup.py | 2 +- tests/test_environment.py | 4 ---- tests/test_fixtures.py | 2 -- tox.ini | 3 +-- 12 files changed, 16 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index a38abce68..c001c0a3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,8 +41,6 @@ matrix: env: TOXENV=py27-pytest3-dj19-postgres - python: 2.7 env: TOXENV=py27-pytest3-dj18-postgres - - python: 2.7 - env: TOXENV=py27-pytest3-dj17-postgres - python: 2.7 env: TOXENV=py27-checkqa diff --git a/README.rst b/README.rst index ad35add35..d42666011 100644 --- a/README.rst +++ b/README.rst @@ -22,7 +22,7 @@ pytest-django allows you to test your Django project/applications with the `_ * Version compatibility: - * Django: 1.7-1.11 and latest master branch (compatible at the time of each release) + * Django: 1.8-1.11 and latest master branch (compatible at the time of each release) * Python: CPython 2.7,3.3-3.6 or PyPy 2,3 * pytest: >2.9.x diff --git a/docs/contributing.rst b/docs/contributing.rst index b67deb5fe..8661dd874 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -137,10 +137,10 @@ writing), running them all will take a long time. All valid configurations can be found in `tox.ini`. To test against a few of them, invoke tox with the `-e` flag:: - $ tox -e python3.3-1.7-postgres,python2.7-1.9-sqlite + $ tox -e python3.6-1.11-postgres,python2.7-1.11-mysql_innodb -This will run the tests on Python 3.3/Django 1.7/PostgeSQL and Python -2.7/Django 1.9/SQLite. +This will run the tests on Python 3.6/Django 1.11/PostgeSQL and Python +2.7/Django 1.11/MySQL. Measuring test coverage diff --git a/docs/helpers.rst b/docs/helpers.rst index ecc415bc2..c1be4258f 100644 --- a/docs/helpers.rst +++ b/docs/helpers.rst @@ -85,7 +85,7 @@ when trying to access the database. If you run pytest using the ``--fail-on-template-vars`` option, tests will fail should your templates contain any invalid variables. This marker will disable this feature by setting ``settings.TEMPLATE_STRING_IF_INVALID=None`` - or the ``string_if_invalid`` template option in Django>=1.7 + or the ``string_if_invalid`` template option Example usage:: diff --git a/docs/managing_python_path.rst b/docs/managing_python_path.rst index bc4233090..32faaa638 100644 --- a/docs/managing_python_path.rst +++ b/docs/managing_python_path.rst @@ -71,7 +71,7 @@ add this directly to your project's requirements.txt file like this:: # requirements.txt -e . - django>=1.7 + django>=1.11 pytest-django diff --git a/pytest_django/compat.py b/pytest_django/compat.py index c427beaf1..df5dfed28 100644 --- a/pytest_django/compat.py +++ b/pytest_django/compat.py @@ -1,4 +1,5 @@ # This file cannot be imported from until Django sets up +from django.db.backends.base.base import BaseDatabaseWrapper try: # Django 1.11 @@ -11,9 +12,3 @@ def teardown_databases(db_cfg, verbosity): (_DiscoverRunner(verbosity=verbosity, interactive=False) .teardown_databases(db_cfg)) - -try: - from django.db.backends.base.base import BaseDatabaseWrapper # noqa -except ImportError: - # Django 1.7. - from django.db.backends import BaseDatabaseWrapper # noqa diff --git a/pytest_django/fixtures.py b/pytest_django/fixtures.py index adc5dea7f..692e0614a 100644 --- a/pytest_django/fixtures.py +++ b/pytest_django/fixtures.py @@ -13,7 +13,7 @@ from .django_compat import is_django_unittest from .pytest_compat import getfixturevalue -from .lazy_django import get_django_version, skip_if_no_django +from .lazy_django import skip_if_no_django __all__ = ['django_db_setup', 'db', 'transactional_db', 'admin_user', 'django_user_model', 'django_username_field', @@ -83,14 +83,7 @@ def django_db_setup( _disable_native_migrations() if django_db_keepdb: - if get_django_version() >= (1, 8): - setup_databases_args['keepdb'] = True - else: - # Django 1.7 compatibility - from .db_reuse import monkey_patch_creation_for_db_reuse - - with django_db_blocker.unblock(): - monkey_patch_creation_for_db_reuse() + setup_databases_args['keepdb'] = True with django_db_blocker.unblock(): db_cfg = setup_databases( diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 4c6961a36..08ae54163 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -34,8 +34,7 @@ from .fixtures import transactional_db # noqa from .pytest_compat import getfixturevalue -from .lazy_django import (django_settings_is_configured, - get_django_version, skip_if_no_django) +from .lazy_django import django_settings_is_configured, skip_if_no_django SETTINGS_MODULE_ENV = 'DJANGO_SETTINGS_MODULE' @@ -63,10 +62,10 @@ def pytest_addoption(parser): help='Set DJANGO_CONFIGURATION.') group._addoption('--nomigrations', '--no-migrations', action='store_true', dest='nomigrations', default=False, - help='Disable Django 1.7+ migrations on test setup') + help='Disable Django migrations on test setup') group._addoption('--migrations', action='store_false', dest='nomigrations', default=False, - help='Enable Django 1.7+ migrations on test setup') + help='Enable Django migrations on test setup') parser.addini(CONFIGURATION_ENV, 'django-configurations class to use by pytest-django.') group._addoption('--liveserver', default=None, @@ -540,7 +539,7 @@ def __mod__(self, var): django_settings_is_configured()): from django.conf import settings as dj_settings - if get_django_version() >= (1, 8) and dj_settings.TEMPLATES: + if dj_settings.TEMPLATES: dj_settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] = ( InvalidVarException()) else: @@ -556,7 +555,7 @@ def _template_string_if_invalid_marker(request): if marker and django_settings_is_configured(): from django.conf import settings as dj_settings - if get_django_version() >= (1, 8) and dj_settings.TEMPLATES: + if dj_settings.TEMPLATES: dj_settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'].fail = False else: dj_settings.TEMPLATE_STRING_IF_INVALID.fail = False diff --git a/tests/test_db_setup.py b/tests/test_db_setup.py index 2ac58658d..07291be9c 100644 --- a/tests/test_db_setup.py +++ b/tests/test_db_setup.py @@ -223,7 +223,7 @@ def test_inner(): class TestNativeMigrations(object): - """ Tests for Django 1.7 Migrations """ + """ Tests for Django Migrations """ def test_no_migrations(self, django_testdir): django_testdir.create_test_module(''' diff --git a/tests/test_environment.py b/tests/test_environment.py index 8411d15f8..e833c3f83 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -225,10 +225,6 @@ def test_more_verbose_with_vv_and_reusedb(self, testdir): not in result.stdout.str()) -@pytest.mark.skipif( - get_django_version() < (1, 8), - reason='Django 1.7 requires settings.SITE_ID to be set, so this test is invalid' -) @pytest.mark.django_db @pytest.mark.parametrize('site_name', ['site1', 'site2']) def test_clear_site_cache(site_name, rf, monkeypatch): diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 969e312de..d03a7d6fb 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -310,8 +310,6 @@ def test_a(self, live_server, settings): result.stdout.fnmatch_lines(['*test_a*PASSED*']) assert result.ret == 0 - @pytest.mark.skipif(get_django_version() < (1, 7), - reason="Django >= 1.7 required") def test_serve_static_dj17_without_staticfiles_app(self, live_server, settings): """ diff --git a/tox.ini b/tox.ini index d28b9f00e..485f85693 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = - py34-pytest3-dj{20,111,110}-postgres - py33-pytest3-dj18-postgres - py27-pytest3-dj{111,110}-{mysql_innodb,mysql_myisam,postgres} - - py27-pytest3-dj{111,110,19,18,17}-postgres + - py27-pytest3-dj{111,110,19,18}-postgres - py{36,py27}-checkqa [testenv] @@ -21,7 +21,6 @@ deps = dj110: Django>=1.10,<1.11 dj19: Django>=1.9,<1.10 dj18: Django>=1.8,<1.9 - dj17: Django>=1.7,<1.8 mysql_myisam: mysql-python==1.2.5 mysql_innodb: mysql-python==1.2.5 From 1a8bfe20feaab4d7e5f6553c035ce0262df7fd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4ufl?= Date: Mon, 9 Oct 2017 12:26:27 +0200 Subject: [PATCH 2/2] Remove BaseDatabaseWrapper from compat --- pytest_django/compat.py | 2 -- pytest_django/plugin.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pytest_django/compat.py b/pytest_django/compat.py index df5dfed28..3baeea9a5 100644 --- a/pytest_django/compat.py +++ b/pytest_django/compat.py @@ -1,6 +1,4 @@ # This file cannot be imported from until Django sets up -from django.db.backends.base.base import BaseDatabaseWrapper - try: # Django 1.11 from django.test.utils import setup_databases, teardown_databases # noqa diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 08ae54163..7f85bcdc7 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -600,7 +600,7 @@ def __init__(self): @property def _dj_db_wrapper(self): - from .compat import BaseDatabaseWrapper + from django.db.backends.base.base import BaseDatabaseWrapper # The first time the _dj_db_wrapper is accessed, we will save a # reference to the real implementation.