Skip to content

Commit 02962fa

Browse files
committed
Merge remote-tracking branch 'upstream/features' into merge-master-into-features
2 parents b77d168 + 1dc16ad commit 02962fa

File tree

6 files changed

+44
-4
lines changed

6 files changed

+44
-4
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.

changelog/4691.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``pytest_terminal_summary`` hook now can also receive a ``config`` parameter.

src/_pytest/hookspec.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,14 @@ def pytest_report_teststatus(report, config):
489489
Stops at first non-None result, see :ref:`firstresult` """
490490

491491

492-
def pytest_terminal_summary(terminalreporter, exitstatus):
492+
def pytest_terminal_summary(terminalreporter, exitstatus, config):
493493
"""Add a section to terminal summary reporting.
494494
495495
:param _pytest.terminal.TerminalReporter terminalreporter: the internal terminal reporter object
496496
:param int exitstatus: the exit status that will be reported back to the OS
497+
:param _pytest.config.Config config: pytest config object
497498
498-
.. versionadded:: 3.5
499+
.. versionadded:: 4.2
499500
The ``config`` parameter.
500501
"""
501502

src/_pytest/terminal.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def pytest_sessionfinish(self, exitstatus):
636636
)
637637
if exitstatus in summary_exit_codes:
638638
self.config.hook.pytest_terminal_summary(
639-
terminalreporter=self, exitstatus=exitstatus
639+
terminalreporter=self, exitstatus=exitstatus, config=self.config
640640
)
641641
if exitstatus == EXIT_INTERRUPTED:
642642
self._report_keyboardinterrupt()
@@ -652,6 +652,7 @@ def pytest_terminal_summary(self):
652652
self.summary_passes()
653653
# Display any extra warnings from teardown here (if any).
654654
self.summary_warnings()
655+
self.summary_deprecated_python()
655656

656657
def pytest_keyboard_interrupt(self, excinfo):
657658
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
@@ -773,6 +774,20 @@ def summary_passes(self):
773774
self.write_sep("_", msg)
774775
self._outrep_summary(rep)
775776

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