Skip to content

Commit

Permalink
Show deprecation message when running under Python 2.7 and 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jan 29, 2019
1 parent 6aba60a commit eb92e57
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog/4627.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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
support those Python versions.
15 changes: 15 additions & 0 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ def pytest_terminal_summary(self):
self.summary_passes()
# Display any extra warnings from teardown here (if any).
self.summary_warnings()
self.summary_deprecated_python()

def pytest_keyboard_interrupt(self, excinfo):
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
Expand Down Expand Up @@ -770,6 +771,20 @@ def summary_passes(self):
self.write_sep("_", msg)
self._outrep_summary(rep)

def summary_deprecated_python(self):
if sys.version_info[:2] <= (3, 4) and self.verbosity >= 0:
self.write_sep("=", "deprecated python version", yellow=True, bold=False)
using_version = ".".join(str(x) for x in sys.version_info[:3])
self.line(
"You are using Python {}, which will no longer be supported in pytest 5.0".format(
using_version
),
yellow=True,
bold=False,
)
self.line("For more information, please read:")
self.line(" https://docs.pytest.org/en/latest/py27-py34-deprecation.html")

def print_teardown_sections(self, rep):
showcapture = self.config.option.showcapture
if showcapture == "no":
Expand Down
4 changes: 3 additions & 1 deletion testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,9 @@ def test_calls_show_2(self, testdir):
result = testdir.runpytest("--durations=2")
assert result.ret == 0
lines = result.stdout.get_lines_after("*slowest*durations*")
assert "4 passed" in lines[2]
# account for the "deprecated python version" header
index = 2 if sys.version_info[:2] > (3, 4) else 6
assert "4 passed" in lines[index]

def test_calls_showall(self, testdir):
testdir.makepyfile(self.source)
Expand Down
19 changes: 19 additions & 0 deletions testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import print_function

import os
import sys

import pytest
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
Expand Down Expand Up @@ -219,3 +220,21 @@ def test_fixture_named_request(testdir):
"*'request' is a reserved name for fixtures and will raise an error in future versions"
]
)


def test_python_deprecation(testdir):
result = testdir.runpytest()
python_ver = ".".join(str(x) for x in sys.version_info[:3])
msg = "You are using Python {}, which will no longer be supported in pytest 5.0".format(
python_ver
)
if sys.version_info[:2] <= (3, 4):
result.stdout.fnmatch_lines(
[
msg,
"For more information, please read:",
" https://docs.pytest.org/en/latest/py27-py34-deprecation.html",
]
)
else:
assert msg not in result.stdout.str()

0 comments on commit eb92e57

Please sign in to comment.