Skip to content

Commit

Permalink
No need to use pytest_cases.parametrize
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Feb 1, 2025
1 parent af8be5f commit 04cae30
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 38 deletions.
7 changes: 3 additions & 4 deletions tests/test_colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import cloup
import pytest
from boltons.strutils import strip_ansi
from pytest_cases import parametrize

from click_extra import (
Color,
Expand Down Expand Up @@ -508,7 +507,7 @@ def command4():


@skip_windows_colors
@parametrize("option_decorator", (color_option, color_option()))
@pytest.mark.parametrize("option_decorator", (color_option, color_option()))
@pytest.mark.parametrize(
("param", "expecting_colors"),
(
Expand Down Expand Up @@ -823,12 +822,12 @@ def test_substring_highlighting(original, substrings, expected, ignore_case):
)


@parametrize(
@pytest.mark.parametrize(
"cmd_decorator, cmd_type",
# Skip click extra's commands, as help option is already part of the default.
command_decorators(no_extra=True, with_types=True),
)
@parametrize("option_decorator", (help_option, help_option()))
@pytest.mark.parametrize("option_decorator", (help_option, help_option()))
def test_standalone_help_option(invoke, cmd_decorator, cmd_type, option_decorator):
@cmd_decorator
@option_decorator
Expand Down
4 changes: 2 additions & 2 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import click
import cloup
import pytest
from pytest_cases import fixture, parametrize
from pytest_cases import fixture

import click_extra
from click_extra import echo, option, option_group, pass_context
Expand Down Expand Up @@ -272,7 +272,7 @@ def test_integrated_version_value(invoke, all_command_cli):
assert result.stdout == "command-cli1, version 2021.10.08\n"


@parametrize(
@pytest.mark.parametrize(
"cmd_decorator",
command_decorators(
no_click=True,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import click
import pytest
from boltons.pathutils import shrinkuser
from pytest_cases import fixture, parametrize
from pytest_cases import fixture

from click_extra import (
command,
Expand Down Expand Up @@ -276,7 +276,7 @@
},
)

all_config_formats = parametrize(
all_config_formats = pytest.mark.parametrize(
("conf_name, conf_text, conf_data"),
(
pytest.param(f"configuration.{ext}", content, data, id=ext)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import click
import pytest
from pytest_cases import parametrize

from click_extra import echo
from click_extra.decorators import extra_command, verbose_option, verbosity_option
Expand Down Expand Up @@ -227,7 +226,7 @@ def logging_cli1():
# Skip click extra's commands, as verbosity option is already part of the default.
command_decorators(no_groups=True, no_extra=True),
)
@parametrize("option_decorator", (verbosity_option, verbosity_option()))
@pytest.mark.parametrize("option_decorator", (verbosity_option, verbosity_option()))
@pytest.mark.parametrize(
("args", "expected_level"),
(
Expand Down
9 changes: 4 additions & 5 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import click
import pytest
from extra_platforms import is_windows
from pytest_cases import parametrize
from tabulate import tabulate

from click_extra import (
Expand Down Expand Up @@ -220,7 +219,7 @@ def envvars_test_cases():
return params


@parametrize("cmd_decorator, envvars, expected_flag", envvars_test_cases())
@pytest.mark.parametrize("cmd_decorator, envvars, expected_flag", envvars_test_cases())
def test_auto_envvar_parsing(invoke, cmd_decorator, envvars, expected_flag):
"""This test highlights the way Click recognize and parse envvars.
Expand Down Expand Up @@ -255,7 +254,7 @@ def convert(self, value, param, ctx):
return value


@parametrize("option_decorator", (show_params_option, show_params_option()))
@pytest.mark.parametrize("option_decorator", (show_params_option, show_params_option()))
def test_params_auto_types(invoke, option_decorator):
"""Check parameters types and structure are properly derived from CLI."""

Expand Down Expand Up @@ -393,8 +392,8 @@ def params_introspection(


# Skip click extra's commands, as show_params option is already part of the default.
@parametrize("cmd_decorator", command_decorators(no_extra=True))
@parametrize("option_decorator", (show_params_option, show_params_option()))
@pytest.mark.parametrize("cmd_decorator", command_decorators(no_extra=True))
@pytest.mark.parametrize("option_decorator", (show_params_option, show_params_option()))
def test_standalone_show_params_option(invoke, cmd_decorator, option_decorator):
@cmd_decorator
@option_decorator
Expand Down
8 changes: 5 additions & 3 deletions tests/test_tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import pytest
import tabulate
from extra_platforms import is_windows
from pytest_cases import fixture, parametrize
from pytest_cases import fixture

# We use vanilla click primitives here to demonstrate the full-compatibility.
from click_extra import echo, pass_context
Expand Down Expand Up @@ -514,8 +514,10 @@ def test_recognized_modes():


@fixture
@parametrize("cmd_decorator", command_decorators(no_groups=True))
@parametrize("option_decorator", (table_format_option, table_format_option()))
@pytest.mark.parametrize("cmd_decorator", command_decorators(no_groups=True))
@pytest.mark.parametrize(
"option_decorator", (table_format_option, table_format_option())
)
def table_cli(cmd_decorator, option_decorator):
@cmd_decorator
@option_decorator
Expand Down
8 changes: 5 additions & 3 deletions tests/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

from textwrap import dedent

from pytest_cases import parametrize
import pytest

from click_extra import command, echo, pass_context, telemetry_option
from click_extra.pytest import command_decorators


@parametrize("cmd_decorator", command_decorators(no_groups=True, no_extra=True))
@parametrize("option_decorator", (telemetry_option, telemetry_option()))
@pytest.mark.parametrize(
"cmd_decorator", command_decorators(no_groups=True, no_extra=True)
)
@pytest.mark.parametrize("option_decorator", (telemetry_option, telemetry_option()))
def test_standalone_telemetry_option(invoke, cmd_decorator, option_decorator):
@cmd_decorator
@option_decorator
Expand Down
4 changes: 2 additions & 2 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import click
import pytest
from extra_platforms import is_windows
from pytest_cases import fixture, parametrize
from pytest_cases import fixture

from click_extra import Style, command, echo, pass_context, secho, style
from click_extra.pytest import command_decorators
Expand Down Expand Up @@ -116,7 +116,7 @@ def run_cli1(ctx):


@fixture
@parametrize("cmd_decorator", command_decorators(no_groups=True))
@pytest.mark.parametrize("cmd_decorator", command_decorators(no_groups=True))
def color_cli(cmd_decorator):
@cmd_decorator
@pass_context
Expand Down
10 changes: 5 additions & 5 deletions tests/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from textwrap import dedent
from time import sleep

from pytest_cases import parametrize
import pytest

from click_extra import echo
from click_extra.decorators import extra_group, timer_option
Expand All @@ -46,7 +46,7 @@ def slow_subcommand():
echo("End of slow subcommand")


@parametrize(
@pytest.mark.parametrize(
"subcommand_id, time_min",
(
("fast", 0.01),
Expand All @@ -67,20 +67,20 @@ def test_integrated_time_option(invoke, subcommand_id, time_min):
assert time_min < float(group.groupdict()["time"]) < 40


@parametrize("subcommand_id", ("fast", "slow"))
@pytest.mark.parametrize("subcommand_id", ("fast", "slow"))
def test_integrated_notime_option(invoke, subcommand_id):
result = invoke(integrated_timer, "--no-time", f"{subcommand_id}-subcommand")
assert result.exit_code == 0
assert not result.stderr
assert result.stdout == f"Start of CLI\nEnd of {subcommand_id} subcommand\n"


@parametrize(
@pytest.mark.parametrize(
"cmd_decorator",
# Skip click extra's commands, as timer option is already part of the default.
command_decorators(no_groups=True, no_extra=True),
)
@parametrize("option_decorator", (timer_option, timer_option()))
@pytest.mark.parametrize("option_decorator", (timer_option, timer_option()))
def test_standalone_timer_option(invoke, cmd_decorator, option_decorator):
@cmd_decorator
@option_decorator
Expand Down
23 changes: 13 additions & 10 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import click
import pytest
from boltons.strutils import strip_ansi
from pytest_cases import parametrize

from click_extra import ExtraVersionOption, Style, __version__, echo, pass_context
from click_extra.decorators import (
Expand All @@ -50,8 +49,10 @@


@skip_windows_colors
@parametrize("cmd_decorator", command_decorators())
@parametrize("option_decorator", (extra_version_option, extra_version_option()))
@pytest.mark.parametrize("cmd_decorator", command_decorators())
@pytest.mark.parametrize(
"option_decorator", (extra_version_option, extra_version_option())
)
def test_standalone_version_option(invoke, cmd_decorator, option_decorator):
@cmd_decorator
@option_decorator
Expand All @@ -67,8 +68,10 @@ def standalone_option():


@skip_windows_colors
@parametrize("cmd_decorator", command_decorators())
@parametrize("option_decorator", (extra_version_option, extra_version_option()))
@pytest.mark.parametrize("cmd_decorator", command_decorators())
@pytest.mark.parametrize(
"option_decorator", (extra_version_option, extra_version_option())
)
def test_debug_output(invoke, cmd_decorator, option_decorator):
@cmd_decorator
@verbosity_option
Expand Down Expand Up @@ -108,8 +111,8 @@ def color_cli2():


@skip_windows_colors
@parametrize("cmd_decorator", command_decorators(no_groups=True))
@parametrize(
@pytest.mark.parametrize("cmd_decorator", command_decorators(no_groups=True))
@pytest.mark.parametrize(
"message, regex_stdout",
(
(
Expand Down Expand Up @@ -154,7 +157,7 @@ def color_cli3():
assert re.fullmatch(regex_stdout, result.output)


@parametrize("cmd_decorator", command_decorators(no_groups=True))
@pytest.mark.parametrize("cmd_decorator", command_decorators(no_groups=True))
def test_style_reset(invoke, cmd_decorator):
@cmd_decorator
@extra_version_option(
Expand All @@ -172,7 +175,7 @@ def color_reset():


@skip_windows_colors
@parametrize("cmd_decorator", command_decorators(no_groups=True))
@pytest.mark.parametrize("cmd_decorator", command_decorators(no_groups=True))
def test_custom_message_style(invoke, cmd_decorator):
@cmd_decorator
@extra_version_option(
Expand All @@ -195,7 +198,7 @@ def custom_style():
)


@parametrize("cmd_decorator", command_decorators(no_groups=True))
@pytest.mark.parametrize("cmd_decorator", command_decorators(no_groups=True))
def test_context_meta(invoke, cmd_decorator):
@cmd_decorator
@extra_version_option
Expand Down

0 comments on commit 04cae30

Please sign in to comment.