Skip to content

Commit 1dc16ad

Browse files
authored
Merge pull request #4690 from nicoddemus/deprecated-python-summary
Show deprecation message when running under Python 2.7 and 3.4
2 parents b41dc03 + eb92e57 commit 1dc16ad

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

changelog/4627.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Display a message at the end of the test session when running under Python 2.7 and 3.4 that pytest 5.0 will no longer
2+
support those Python versions.

src/_pytest/terminal.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ def pytest_terminal_summary(self):
649649
self.summary_passes()
650650
# Display any extra warnings from teardown here (if any).
651651
self.summary_warnings()
652+
self.summary_deprecated_python()
652653

653654
def pytest_keyboard_interrupt(self, excinfo):
654655
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
@@ -770,6 +771,20 @@ def summary_passes(self):
770771
self.write_sep("_", msg)
771772
self._outrep_summary(rep)
772773

774+
def summary_deprecated_python(self):
775+
if sys.version_info[:2] <= (3, 4) and self.verbosity >= 0:
776+
self.write_sep("=", "deprecated python version", yellow=True, bold=False)
777+
using_version = ".".join(str(x) for x in sys.version_info[:3])
778+
self.line(
779+
"You are using Python {}, which will no longer be supported in pytest 5.0".format(
780+
using_version
781+
),
782+
yellow=True,
783+
bold=False,
784+
)
785+
self.line("For more information, please read:")
786+
self.line(" https://docs.pytest.org/en/latest/py27-py34-deprecation.html")
787+
773788
def print_teardown_sections(self, rep):
774789
showcapture = self.config.option.showcapture
775790
if showcapture == "no":

testing/acceptance_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,9 @@ def test_calls_show_2(self, testdir):
854854
result = testdir.runpytest("--durations=2")
855855
assert result.ret == 0
856856
lines = result.stdout.get_lines_after("*slowest*durations*")
857-
assert "4 passed" in lines[2]
857+
# account for the "deprecated python version" header
858+
index = 2 if sys.version_info[:2] > (3, 4) else 6
859+
assert "4 passed" in lines[index]
858860

859861
def test_calls_showall(self, testdir):
860862
testdir.makepyfile(self.source)

testing/deprecated_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import print_function
44

55
import os
6+
import sys
67

78
import pytest
89
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
@@ -219,3 +220,21 @@ def test_fixture_named_request(testdir):
219220
"*'request' is a reserved name for fixtures and will raise an error in future versions"
220221
]
221222
)
223+
224+
225+
def test_python_deprecation(testdir):
226+
result = testdir.runpytest()
227+
python_ver = ".".join(str(x) for x in sys.version_info[:3])
228+
msg = "You are using Python {}, which will no longer be supported in pytest 5.0".format(
229+
python_ver
230+
)
231+
if sys.version_info[:2] <= (3, 4):
232+
result.stdout.fnmatch_lines(
233+
[
234+
msg,
235+
"For more information, please read:",
236+
" https://docs.pytest.org/en/latest/py27-py34-deprecation.html",
237+
]
238+
)
239+
else:
240+
assert msg not in result.stdout.str()

0 commit comments

Comments
 (0)