Skip to content

Commit d81a115

Browse files
committed
pastebin: deprecate --pastebin
Fix #14434
1 parent b106128 commit d81a115

5 files changed

Lines changed: 45 additions & 2 deletions

File tree

changelog/14434.deprecation.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :option:`--pastebin` option is now deprecated.
2+
The same functionality is now available in an external plugin, :pypi:`pytest-pastebin`.
3+
See :ref:`pastebin-deprecated` for more details.

doc/en/deprecations.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ Below is a complete list of all pytest features which are considered deprecated.
1515
:class:`~pytest.PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters <warnings>`.
1616

1717

18+
.. _pastebin-deprecated:
19+
20+
The ``--pastebin`` option
21+
~~~~~~~~~~~~~~~~~~~~~~~~~
22+
23+
.. deprecated:: 9.1
24+
25+
The :option:`--pastebin` option has been deprecated due to being very niche, being the only feature in core pytest relying on an external service and having low usage.
26+
27+
The plugin which implements ``--pastebin`` has been extracted to a separate package, :pypi:`pytest-pastebin`.
28+
Please install ``pytest-pastebin`` if you want to keep using ``--pastebin``.
29+
30+
1831
.. _dynamic-fixture-request-during-teardown:
1932

2033
``request.getfixturevalue()`` during fixture teardown

src/_pytest/deprecated.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
"See https://docs.pytest.org/en/stable/deprecations.html#dynamic-fixture-request-during-teardown",
7676
)
7777

78+
PASTEBIN = PytestRemovedIn10Warning(
79+
"The --pastebin option is deprecated. "
80+
"The functionality is now available in an external plugin package, pytest-pastebin.\n"
81+
"See https://docs.pytest.org/en/stable/deprecations.html#the-pastebin-option"
82+
)
83+
7884
# You want to make some `__init__` or function "private".
7985
#
8086
# def my_private_function(some, args):

src/_pytest/pastebin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from _pytest.config import Config
1111
from _pytest.config import create_terminal_writer
1212
from _pytest.config.argparsing import Parser
13+
from _pytest.deprecated import PASTEBIN
1314
from _pytest.stash import StashKey
1415
from _pytest.terminal import TerminalReporter
1516
import pytest
@@ -33,6 +34,9 @@ def pytest_addoption(parser: Parser) -> None:
3334

3435
@pytest.hookimpl(trylast=True)
3536
def pytest_configure(config: Config) -> None:
37+
if config.option.pastebin:
38+
config.issue_config_time_warning(PASTEBIN, 2)
39+
3640
if config.option.pastebin == "all":
3741
tr = config.pluginmanager.getplugin("terminalreporter")
3842
# If no terminal reporter plugin is present, nothing we can do here;

testing/test_pastebin.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io
66
from unittest import mock
77

8+
from _pytest.config import ExitCode
89
from _pytest.monkeypatch import MonkeyPatch
910
from _pytest.pytester import Pytester
1011
import pytest
@@ -50,7 +51,13 @@ def test_skip():
5051
pytest.skip("")
5152
"""
5253
)
53-
reprec = pytester.inline_run(testpath, "--pastebin=all", "-v")
54+
reprec = pytester.inline_run(
55+
testpath,
56+
"--pastebin=all",
57+
"-v",
58+
"-W",
59+
"ignore:The --pastebin:DeprecationWarning",
60+
)
5461
assert reprec.countoutcomes() == [1, 1, 1]
5562
assert len(pastebinlist) == 1
5663
contents = pastebinlist[0].decode("utf-8")
@@ -74,7 +81,11 @@ def test():
7481
assert '☺' == 1
7582
"""
7683
)
77-
result = pytester.runpytest("--pastebin=all")
84+
result = pytester.runpytest(
85+
"--pastebin=all",
86+
"-W",
87+
"ignore:The --pastebin:DeprecationWarning",
88+
)
7889
expected_msg = "*assert '☺' == 1*"
7990
result.stdout.fnmatch_lines(
8091
[
@@ -85,6 +96,12 @@ def test():
8596
)
8697
assert len(pastebinlist) == 1
8798

99+
def test_deprecated(self, pytester: Pytester, pastebinlist) -> None:
100+
result = pytester.runpytest("--pastebin=failed")
101+
assert result.ret == ExitCode.NO_TESTS_COLLECTED
102+
result.assert_outcomes()
103+
result.stdout.fnmatch_lines(["*The --pastebin option is deprecated*"])
104+
88105

89106
class TestPaste:
90107
@pytest.fixture

0 commit comments

Comments
 (0)