Skip to content

Commit e8495d0

Browse files
committed
Deduplicate pytest markers for Click 8/not Click 8
1 parent 693bfca commit e8495d0

3 files changed

Lines changed: 11 additions & 34 deletions

File tree

consolekit/testing.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,8 @@ def cli_runner() -> CliRunner:
307307
"""
308308

309309
return CliRunner()
310+
311+
312+
# Helpers for tests whose output depends on Click major version.
313+
click_8_only = pytest.mark.skipif(_click_version[0] == 8, reason="Output differs on click 8")
314+
not_click_8 = pytest.mark.skipif(_click_version[0] != 8, reason="Output differs on click 8")

tests/test_input.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# this package
1212
from consolekit.input import choice, confirm, prompt
13-
from consolekit.testing import _click_version
13+
from consolekit.testing import click_8_only, not_click_8
1414

1515

1616
def test_choice_letters(
@@ -45,16 +45,7 @@ def fake_input(prompt: str) -> str:
4545

4646
@pytest.mark.parametrize(
4747
"click_version",
48-
[
49-
pytest.param(
50-
'7',
51-
marks=pytest.mark.skipif(_click_version[0] == 8, reason="Output differs on click 8"),
52-
),
53-
pytest.param(
54-
'8',
55-
marks=pytest.mark.skipif(_click_version[0] != 8, reason="Output differs on click 8"),
56-
),
57-
]
48+
[pytest.param('7', marks=click_8_only), pytest.param('8', marks=not_click_8)],
5849
)
5950
def test_choice_numbers(
6051
capsys,

tests/test_tracebacks.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# this package
1212
from consolekit import click_command
13-
from consolekit.testing import CliRunner, Result, _click_version
13+
from consolekit.testing import CliRunner, Result, click, click_8_only, not_click_8
1414
from consolekit.tracebacks import TracebackHandler, handle_tracebacks, traceback_handler, traceback_option
1515

1616
exceptions = pytest.mark.parametrize(
@@ -110,34 +110,15 @@ def test_handle_tracebacks_ignored_exceptions(
110110
[
111111
pytest.param(click.UsageError("Message"), 2, id="click.UsageError"),
112112
pytest.param(click.BadParameter("Message"), 2, id="click.BadParameter"),
113-
pytest.param(
114-
click.FileError("Message"),
115-
1,
116-
id="click.FileError",
117-
marks=pytest.mark.skipif(_click_version[0] == 8, reason="Output differs on Click 8")
118-
),
119-
pytest.param(
120-
click.FileError("Message"),
121-
1,
122-
id="click.FileError_8",
123-
marks=pytest.mark.skipif(_click_version[0] != 8, reason="Output differs on Click 8")
124-
),
113+
pytest.param(click.FileError("Message"), 1, id="click.FileError", marks=click_8_only),
114+
pytest.param(click.FileError("Message"), 1, id="click.FileError_8", marks=not_click_8),
125115
pytest.param(click.ClickException("Message"), 1, id="click.ClickException"),
126116
]
127117
)
128118
@contextmanagers
129119
@pytest.mark.parametrize(
130120
"click_version",
131-
[
132-
pytest.param(
133-
'7',
134-
marks=pytest.mark.skipif(_click_version[0] == 8, reason="Output differs on click 8"),
135-
),
136-
pytest.param(
137-
'8',
138-
marks=pytest.mark.skipif(_click_version[0] != 8, reason="Output differs on click 8"),
139-
),
140-
]
121+
[pytest.param('7', marks=click_8_only), pytest.param('8', marks=not_click_8)],
141122
)
142123
def test_handle_tracebacks_ignored_click(
143124
exception: Exception,

0 commit comments

Comments
 (0)