From 10c339dff8b1ec5361a6b73252afe73cc98bfe86 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 29 Jan 2019 15:31:20 -0200 Subject: [PATCH] Show deprecation message when running under Python 2.7 and 3.4 Fix #4627 --- changelog/4627.feature.rst | 2 ++ src/_pytest/terminal.py | 15 +++++++++++++++ testing/deprecated_test.py | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 changelog/4627.feature.rst diff --git a/changelog/4627.feature.rst b/changelog/4627.feature.rst new file mode 100644 index 00000000000..22bb0618f5e --- /dev/null +++ b/changelog/4627.feature.rst @@ -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. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 3c6504b666a..3ee36b50be4 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -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) @@ -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": diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index a6ef4739bc4..92cfcbff88c 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -3,6 +3,7 @@ from __future__ import print_function import os +import sys import pytest from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG @@ -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()