diff --git a/changelog/4627.feature.rst b/changelog/4627.feature.rst new file mode 100644 index 000000000..22bb0618f --- /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/changelog/4691.feature.rst b/changelog/4691.feature.rst new file mode 100644 index 000000000..8206d0569 --- /dev/null +++ b/changelog/4691.feature.rst @@ -0,0 +1 @@ +``pytest_terminal_summary`` hook now can also receive a ``config`` parameter. diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 4f346ba25..3b6c9a7d1 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -489,13 +489,14 @@ def pytest_report_teststatus(report, config): Stops at first non-None result, see :ref:`firstresult` """ -def pytest_terminal_summary(terminalreporter, exitstatus): +def pytest_terminal_summary(terminalreporter, exitstatus, config): """Add a section to terminal summary reporting. :param _pytest.terminal.TerminalReporter terminalreporter: the internal terminal reporter object :param int exitstatus: the exit status that will be reported back to the OS + :param _pytest.config.Config config: pytest config object - .. versionadded:: 3.5 + .. versionadded:: 4.2 The ``config`` parameter. """ diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index d4ca8a7ae..03b0761f2 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -636,7 +636,7 @@ class TerminalReporter(object): ) if exitstatus in summary_exit_codes: self.config.hook.pytest_terminal_summary( - terminalreporter=self, exitstatus=exitstatus + terminalreporter=self, exitstatus=exitstatus, config=self.config ) if exitstatus == EXIT_INTERRUPTED: self._report_keyboardinterrupt() @@ -652,6 +652,7 @@ class TerminalReporter(object): 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) @@ -773,6 +774,20 @@ class TerminalReporter(object): 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/acceptance_test.py b/testing/acceptance_test.py index af30f2123..c8a391b78 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -854,7 +854,9 @@ class TestDurations(object): 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) diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index a6ef4739b..92cfcbff8 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -3,6 +3,7 @@ from __future__ import division 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()