Skip to content

Commit ce61e04

Browse files
committed
Drop support for Python<3.5, Django<2.2, pytest<5.4
1 parent 9d91f0b commit ce61e04

27 files changed

+142
-429
lines changed

.travis.yml

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,61 @@
11
language: python
2-
dist: xenial
2+
dist: focal
33
cache: false
44

55
jobs:
66
fast_finish: true
77
include:
88
- stage: baseline
9-
python: 3.6
9+
python: 3.8
1010
env:
11-
- TOXENV=py36-dj20-postgres-xdist-coverage
11+
- TOXENV=py38-dj31-postgres-xdist-coverage
1212
# Test in verbose mode.
1313
- PYTEST_ADDOPTS=-vv
1414
services:
1515
- postgresql
16-
- python: 3.6
17-
env: TOXENV=py36-dj111-mysql_innodb-coverage
16+
- python: 3.7
17+
env: TOXENV=py37-dj30-mysql_innodb-coverage
1818
services:
1919
- mysql
20-
- python: 2.7
21-
env: TOXENV=py27-dj111-sqlite-xdist-coverage
2220
- python: 3.6
21+
env: TOXENV=py36-dj22-sqlite-xdist-coverage
22+
- python: 3.8
2323
env: TOXENV=checkqa,docs
2424

2525
- stage: test
2626
python: 3.7
27-
env: TOXENV=py37-dj21-sqlite-coverage
28-
- python: 3.7
2927
env: TOXENV=py37-dj22-sqlite-xdist-coverage
3028
- python: 3.8
3129
env: TOXENV=py38-dj30-sqlite-xdist-coverage
3230
- python: 3.8
3331
env: TOXENV=py38-dj31-sqlite-xdist-coverage
3432

35-
# Explicitly test (older) pytest 4.1.
36-
- python: 3.7
37-
env: TOXENV=py37-dj21-sqlite-pytest41-coverage
38-
39-
- python: 3.6
40-
env: TOXENV=py36-djmaster-sqlite-coverage
33+
- python: 3.8
34+
env: TOXENV=py38-djmaster-sqlite-coverage
4135

42-
# Explicitly test (older) pytest 5.3.
36+
# Explicitly test (older) pytest 5.4.
4337
- python: 3.5
44-
env: TOXENV=py35-dj110-postgres-pytest53-coverage
38+
env: TOXENV=py35-dj22-postgres-pytest54-coverage
4539
services:
4640
- postgresql
4741

48-
- python: 3.4
49-
env: TOXENV=py34-dj19-sqlite_file-coverage
42+
- python: 3.5
43+
env: TOXENV=py35-dj22-sqlite_file-coverage
5044

51-
- python: 2.7
52-
env: TOXENV=py27-dj111-mysql_myisam-coverage
45+
- python: 3.6
46+
env: TOXENV=py36-dj31-mysql_myisam-coverage
5347
services:
5448
- mysql
55-
- python: 2.7
56-
env: TOXENV=py27-dj18-postgres-coverage
57-
services:
58-
- postgresql
5949

60-
# pypy/pypy3: not included with coverage reports (much slower then).
61-
- python: pypy
62-
env: TOXENV=pypy-dj111-sqlite_file
50+
# pypy3: not included with coverage reports (much slower then).
6351
- python: pypy3
64-
env: TOXENV=pypy3-dj110-sqlite
52+
env: TOXENV=pypy3-dj22-postgres
53+
services:
54+
- postgresql
6555

6656
- stage: test_release
67-
python: 3.6
68-
env: TOXENV=py36-dj20-postgres
57+
python: 3.8
58+
env: TOXENV=py38-dj31-postgres
6959
services:
7060
- postgresql
7161

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

9080
stages:
9181
- name: baseline
@@ -98,7 +88,7 @@ stages:
9888
if: tag IS present
9989

10090
install:
101-
- pip install tox==3.9.0
91+
- pip install tox==3.20.0
10292

10393
script:
10494
- tox

README.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ pytest-django allows you to test your Django project/applications with the
2828
<https://pytest-django.readthedocs.io/en/latest/contributing.html>`_
2929
* Version compatibility:
3030

31-
* Django: 1.8-1.11, 2.0-2.2,
32-
and latest master branch (compatible at the time of each release)
33-
* Python: CPython 2.7, 3.4-3.7 or PyPy 2, 3
34-
* pytest: >=3.6
31+
* Django: 2.2, 3.0, 3.1 and latest master branch (compatible at the time of
32+
each release)
33+
* Python: CPython>=3.5 or PyPy 3
34+
* pytest: >=5.4
35+
36+
For compatibility with older versions, use the pytest-django 3.*.* series.
3537

3638
* Licence: BSD
3739
* Project maintainers: Andreas Pelme, Floris Bruynooghe and Daniel Hahler

docs/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import os
42
import sys
53
import datetime

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test runner like this:
7676

7777
.. code-block:: python
7878
79-
class PytestTestRunner(object):
79+
class PytestTestRunner:
8080
"""Runs pytest to discover and run tests."""
8181
8282
def __init__(self, verbosity=1, failfast=False, keepdb=False, **kwargs):

pytest_django/asserts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def assertion_func(*args, **kwargs):
2323
__all__ = []
2424
assertions_names = set()
2525
assertions_names.update(
26-
set(attr for attr in vars(TestCase) if attr.startswith('assert')),
27-
set(attr for attr in vars(SimpleTestCase) if attr.startswith('assert')),
28-
set(attr for attr in vars(LiveServerTestCase) if attr.startswith('assert')),
29-
set(attr for attr in vars(TransactionTestCase) if attr.startswith('assert')),
26+
{attr for attr in vars(TestCase) if attr.startswith('assert')},
27+
{attr for attr in vars(SimpleTestCase) if attr.startswith('assert')},
28+
{attr for attr in vars(LiveServerTestCase) if attr.startswith('assert')},
29+
{attr for attr in vars(TransactionTestCase) if attr.startswith('assert')},
3030
)
3131

3232
for assert_func in assertions_names:

pytest_django/compat.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

pytest_django/fixtures.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""All pytest-django fixtures"""
22

3-
from __future__ import with_statement
43

54
import os
6-
import warnings
75
from contextlib import contextmanager
86
from 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\nQueries:\n========\n\n%s" % "\n\n".join(sqls)
448+
msg += "\n\nQueries:\n========\n\n" + "\n\n".join(sqls)
469449
else:
470450
msg += " (add -v option to show queries)"
471451
pytest.fail(msg)

pytest_django/live_server_helper.py

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import six
2-
3-
4-
@six.python_2_unicode_compatible
5-
class LiveServer(object):
1+
class LiveServer:
62
"""The liveserver fixture
73
84
This is the object that the ``live_server`` fixture returns.
95
The ``live_server`` fixture handles creation and stopping.
106
"""
117

128
def __init__(self, addr):
13-
import django
149
from django.db import connections
1510
from django.test.testcases import LiveServerThread
1611
from django.test.utils import modify_settings
@@ -39,17 +34,13 @@ def __init__(self, addr):
3934

4035
liveserver_kwargs["static_handler"] = _StaticFilesHandler
4136

42-
if django.VERSION < (1, 11):
43-
host, possible_ports = parse_addr(addr)
44-
self.thread = LiveServerThread(host, possible_ports, **liveserver_kwargs)
37+
try:
38+
host, port = addr.split(":")
39+
except ValueError:
40+
host = addr
4541
else:
46-
try:
47-
host, port = addr.split(":")
48-
except ValueError:
49-
host = addr
50-
else:
51-
liveserver_kwargs["port"] = int(port)
52-
self.thread = LiveServerThread(host, **liveserver_kwargs)
42+
liveserver_kwargs["port"] = int(port)
43+
self.thread = LiveServerThread(host, **liveserver_kwargs)
5344

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

7061
@property
7162
def url(self):
72-
return "http://%s:%s" % (self.thread.host, self.thread.port)
63+
return "http://{}:{}".format(self.thread.host, self.thread.port)
7364

7465
def __str__(self):
7566
return self.url
7667

7768
def __add__(self, other):
78-
return "%s%s" % (self, other)
69+
return "{}{}".format(self, other)
7970

8071
def __repr__(self):
8172
return "<LiveServer listening at %s>" % self.url
82-
83-
84-
def parse_addr(specified_address):
85-
"""Parse the --liveserver argument into a host/IP address and port range"""
86-
# This code is based on
87-
# django.test.testcases.LiveServerTestCase.setUpClass
88-
89-
# The specified ports may be of the form '8000-8010,8080,9200-9300'
90-
# i.e. a comma-separated list of ports or ranges of ports, so we break
91-
# it down into a detailed list of all possible ports.
92-
possible_ports = []
93-
try:
94-
host, port_ranges = specified_address.split(":")
95-
for port_range in port_ranges.split(","):
96-
# A port range can be of either form: '8000' or '8000-8010'.
97-
extremes = list(map(int, port_range.split("-")))
98-
assert len(extremes) in (1, 2)
99-
if len(extremes) == 1:
100-
# Port range of the form '8000'
101-
possible_ports.append(extremes[0])
102-
else:
103-
# Port range of the form '8000-8010'
104-
for port in range(extremes[0], extremes[1] + 1):
105-
possible_ports.append(port)
106-
except Exception:
107-
raise Exception('Invalid address ("%s") for live server.' % specified_address)
108-
109-
return host, possible_ports

pytest_django/migrations.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
from pytest_django.lazy_django import get_django_version
33

44

5-
class DisableMigrations(object):
5+
class DisableMigrations:
66
def __init__(self):
77
self._django_version = get_django_version()
88

99
def __contains__(self, item):
1010
return True
1111

1212
def __getitem__(self, item):
13-
if self._django_version >= (1, 9):
14-
return None
15-
else:
16-
return "notmigrations"
13+
return None

0 commit comments

Comments
 (0)