Skip to content

Drop support for Python<3.5, Django<2.2, pytest<5.4 #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,61 @@
language: python
dist: xenial
dist: focal
cache: false

jobs:
fast_finish: true
include:
- stage: baseline
python: 3.6
python: 3.8
env:
- TOXENV=py36-dj20-postgres-xdist-coverage
- TOXENV=py38-dj31-postgres-xdist-coverage
# Test in verbose mode.
- PYTEST_ADDOPTS=-vv
services:
- postgresql
- python: 3.6
env: TOXENV=py36-dj111-mysql_innodb-coverage
- python: 3.7
env: TOXENV=py37-dj30-mysql_innodb-coverage
services:
- mysql
- python: 2.7
env: TOXENV=py27-dj111-sqlite-xdist-coverage
- python: 3.6
env: TOXENV=py36-dj22-sqlite-xdist-coverage
- python: 3.8
env: TOXENV=checkqa,docs

- stage: test
python: 3.7
env: TOXENV=py37-dj21-sqlite-coverage
- python: 3.7
env: TOXENV=py37-dj22-sqlite-xdist-coverage
- python: 3.8
env: TOXENV=py38-dj30-sqlite-xdist-coverage
- python: 3.8
env: TOXENV=py38-dj31-sqlite-xdist-coverage

# Explicitly test (older) pytest 4.1.
- python: 3.7
env: TOXENV=py37-dj21-sqlite-pytest41-coverage

- python: 3.6
env: TOXENV=py36-djmaster-sqlite-coverage
- python: 3.8
env: TOXENV=py38-djmaster-sqlite-coverage

# Explicitly test (older) pytest 5.3.
# Explicitly test (older) pytest 5.4.
- python: 3.5
env: TOXENV=py35-dj110-postgres-pytest53-coverage
env: TOXENV=py35-dj22-postgres-pytest54-coverage
services:
- postgresql

- python: 3.4
env: TOXENV=py34-dj19-sqlite_file-coverage
- python: 3.5
env: TOXENV=py35-dj22-sqlite_file-coverage

- python: 2.7
env: TOXENV=py27-dj111-mysql_myisam-coverage
- python: 3.6
env: TOXENV=py36-dj31-mysql_myisam-coverage
services:
- mysql
- python: 2.7
env: TOXENV=py27-dj18-postgres-coverage
services:
- postgresql

# pypy/pypy3: not included with coverage reports (much slower then).
- python: pypy
env: TOXENV=pypy-dj111-sqlite_file
# pypy3: not included with coverage reports (much slower then).
- python: pypy3
env: TOXENV=pypy3-dj110-sqlite
env: TOXENV=pypy3-dj22-postgres
services:
- postgresql

- stage: test_release
python: 3.6
env: TOXENV=py36-dj20-postgres
python: 3.8
env: TOXENV=py38-dj31-postgres
services:
- postgresql

Expand All @@ -85,7 +75,7 @@ jobs:
# NOTE: does not show up in "allowed failures" section, but is allowed to
# fail (for the "test" stage).
allow_failures:
- env: TOXENV=py36-djmaster-sqlite-coverage
- env: TOXENV=py38-djmaster-sqlite-coverage

stages:
- name: baseline
Expand All @@ -98,7 +88,7 @@ stages:
if: tag IS present

install:
- pip install tox==3.9.0
- pip install tox==3.20.0

script:
- tox
Expand Down
10 changes: 6 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ pytest-django allows you to test your Django project/applications with the
<https://pytest-django.readthedocs.io/en/latest/contributing.html>`_
* Version compatibility:

* Django: 1.8-1.11, 2.0-2.2,
and latest master branch (compatible at the time of each release)
* Python: CPython 2.7, 3.4-3.7 or PyPy 2, 3
* pytest: >=3.6
* Django: 2.2, 3.0, 3.1 and latest master branch (compatible at the time of
each release)
* Python: CPython>=3.5 or PyPy 3
* pytest: >=5.4

For compatibility with older versions, use the pytest-django 3.*.* series.

* Licence: BSD
* Project maintainers: Andreas Pelme, Floris Bruynooghe and Daniel Hahler
Expand Down
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import os
import sys
import datetime
Expand Down
2 changes: 1 addition & 1 deletion docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test runner like this:

.. code-block:: python

class PytestTestRunner(object):
class PytestTestRunner:
"""Runs pytest to discover and run tests."""

def __init__(self, verbosity=1, failfast=False, keepdb=False, **kwargs):
Expand Down
8 changes: 4 additions & 4 deletions pytest_django/asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def assertion_func(*args, **kwargs):
__all__ = []
assertions_names = set()
assertions_names.update(
set(attr for attr in vars(TestCase) if attr.startswith('assert')),
set(attr for attr in vars(SimpleTestCase) if attr.startswith('assert')),
set(attr for attr in vars(LiveServerTestCase) if attr.startswith('assert')),
set(attr for attr in vars(TransactionTestCase) if attr.startswith('assert')),
{attr for attr in vars(TestCase) if attr.startswith('assert')},
{attr for attr in vars(SimpleTestCase) if attr.startswith('assert')},
{attr for attr in vars(LiveServerTestCase) if attr.startswith('assert')},
{attr for attr in vars(TransactionTestCase) if attr.startswith('assert')},
)

for assert_func in assertions_names:
Expand Down
12 changes: 0 additions & 12 deletions pytest_django/compat.py

This file was deleted.

36 changes: 8 additions & 28 deletions pytest_django/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""All pytest-django fixtures"""

from __future__ import with_statement

import os
import warnings
from contextlib import contextmanager
from functools import partial

Expand Down Expand Up @@ -91,7 +89,7 @@ def django_db_setup(
django_db_modify_db_settings,
):
"""Top level fixture to ensure test databases are available"""
from .compat import setup_databases, teardown_databases
from django.test.utils import setup_databases, teardown_databases

setup_databases_args = {}

Expand Down Expand Up @@ -164,7 +162,7 @@ def _disable_native_migrations():
class MigrateSilentCommand(migrate.Command):
def handle(self, *args, **kwargs):
kwargs["verbosity"] = 0
return super(MigrateSilentCommand, self).handle(*args, **kwargs)
return super().handle(*args, **kwargs)

migrate.Command = MigrateSilentCommand

Expand Down Expand Up @@ -320,7 +318,7 @@ def rf():
return RequestFactory()


class SettingsWrapper(object):
class SettingsWrapper:
_to_restore = []

def __delattr__(self, attr):
Expand Down Expand Up @@ -370,8 +368,8 @@ def live_server(request):
The address the server is started from is taken from the
--liveserver command line option or if this is not provided from
the DJANGO_LIVE_TEST_SERVER_ADDRESS environment variable. If
neither is provided ``localhost:8081,8100-8200`` is used. See the
Django documentation for its full syntax.
neither is provided ``localhost`` is used. See the Django
documentation for its full syntax.

NOTE: If the live server needs database access to handle a request
your test will have to request database access. Furthermore
Expand All @@ -385,27 +383,9 @@ def live_server(request):
"""
skip_if_no_django()

import django

addr = request.config.getvalue("liveserver") or os.getenv(
"DJANGO_LIVE_TEST_SERVER_ADDRESS"
)

if addr and ":" in addr:
if django.VERSION >= (1, 11):
ports = addr.split(":")[1]
if "-" in ports or "," in ports:
warnings.warn(
"Specifying multiple live server ports is not supported "
"in Django 1.11. This will be an error in a future "
"pytest-django release."
)

if not addr:
if django.VERSION < (1, 11):
addr = "localhost:8081,8100-8200"
else:
addr = "localhost"
) or "localhost"

server = live_server_helper.LiveServer(addr)
request.addfinalizer(server.stop)
Expand Down Expand Up @@ -458,14 +438,14 @@ def _assert_num_queries(config, num, exact=True, connection=None, info=None):
num,
"" if exact else "or less ",
"but {} done".format(
num_performed == 1 and "1 was" or "%d were" % (num_performed,)
num_performed == 1 and "1 was" or "{} were".format(num_performed)
),
)
if info:
msg += "\n{}".format(info)
if verbose:
sqls = (q["sql"] for q in context.captured_queries)
msg += "\n\nQueries:\n========\n\n%s" % "\n\n".join(sqls)
msg += "\n\nQueries:\n========\n\n" + "\n\n".join(sqls)
else:
msg += " (add -v option to show queries)"
pytest.fail(msg)
Expand Down
55 changes: 9 additions & 46 deletions pytest_django/live_server_helper.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import six


@six.python_2_unicode_compatible
class LiveServer(object):
class LiveServer:
"""The liveserver fixture

This is the object that the ``live_server`` fixture returns.
The ``live_server`` fixture handles creation and stopping.
"""

def __init__(self, addr):
import django
from django.db import connections
from django.test.testcases import LiveServerThread
from django.test.utils import modify_settings
Expand Down Expand Up @@ -39,17 +34,13 @@ def __init__(self, addr):

liveserver_kwargs["static_handler"] = _StaticFilesHandler

if django.VERSION < (1, 11):
host, possible_ports = parse_addr(addr)
self.thread = LiveServerThread(host, possible_ports, **liveserver_kwargs)
try:
host, port = addr.split(":")
except ValueError:
host = addr
else:
try:
host, port = addr.split(":")
except ValueError:
host = addr
else:
liveserver_kwargs["port"] = int(port)
self.thread = LiveServerThread(host, **liveserver_kwargs)
liveserver_kwargs["port"] = int(port)
self.thread = LiveServerThread(host, **liveserver_kwargs)

self._live_server_modified_settings = modify_settings(
ALLOWED_HOSTS={"append": host}
Expand All @@ -69,41 +60,13 @@ def stop(self):

@property
def url(self):
return "http://%s:%s" % (self.thread.host, self.thread.port)
return "http://{}:{}".format(self.thread.host, self.thread.port)

def __str__(self):
return self.url

def __add__(self, other):
return "%s%s" % (self, other)
return "{}{}".format(self, other)

def __repr__(self):
return "<LiveServer listening at %s>" % self.url


def parse_addr(specified_address):
"""Parse the --liveserver argument into a host/IP address and port range"""
# This code is based on
# django.test.testcases.LiveServerTestCase.setUpClass

# The specified ports may be of the form '8000-8010,8080,9200-9300'
# i.e. a comma-separated list of ports or ranges of ports, so we break
# it down into a detailed list of all possible ports.
possible_ports = []
try:
host, port_ranges = specified_address.split(":")
for port_range in port_ranges.split(","):
# A port range can be of either form: '8000' or '8000-8010'.
extremes = list(map(int, port_range.split("-")))
assert len(extremes) in (1, 2)
if len(extremes) == 1:
# Port range of the form '8000'
possible_ports.append(extremes[0])
else:
# Port range of the form '8000-8010'
for port in range(extremes[0], extremes[1] + 1):
possible_ports.append(port)
except Exception:
raise Exception('Invalid address ("%s") for live server.' % specified_address)

return host, possible_ports
7 changes: 2 additions & 5 deletions pytest_django/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
from pytest_django.lazy_django import get_django_version


class DisableMigrations(object):
class DisableMigrations:
def __init__(self):
self._django_version = get_django_version()

def __contains__(self, item):
return True

def __getitem__(self, item):
if self._django_version >= (1, 9):
return None
else:
return "notmigrations"
return None
Loading