Skip to content

Commit

Permalink
fix: Add support for pytest>=7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGotelli committed Aug 23, 2024
1 parent 6148c29 commit f79f5ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ packages = [

[tool.poetry.dependencies]
python = "^3.10"
pytest = ">=7.0.0, <9.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.2"
black = "^24.8.0"
pylint = "^3.2.6"
coverage = "^7.6.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import IO

from _pytest._io.pprint import PrettyPrinter
try:
from _pytest._io.pprint import PrettyPrinter
except ImportError: # pragma: no cover
from pprint import PrettyPrinter

from pytest_matchers.matchers import Matcher

Expand Down
16 changes: 16 additions & 0 deletions src/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from src.tests.conftest import CustomEqual


def _low_pytest_version():
return int(pytest.__version__[0]) < 8


@pytest.fixture(autouse=True)
def _set_verbosity(request):
previous_verbosity = request.config.option.verbose
Expand Down Expand Up @@ -42,6 +46,10 @@ def _expected_list_diff(results: list) -> str:
return "\n ".join(message)


@pytest.mark.skipif(
_low_pytest_version(),
reason="The custom assert_repr is only available in pytest 8 or higher.",
)
def test_non_custom_assert_repr():
actual = "string"
expected = is_instance(int)
Expand Down Expand Up @@ -87,6 +95,10 @@ def test_custom_assert_repr_dictionary():
assert str(error) == _expected_warning(actual, expected, "==")


@pytest.mark.skipif(
_low_pytest_version(),
reason="The custom assert_repr is only available in pytest 8 or higher.",
)
def test_custom_assert_repr_dictionary_matcher_replace():
custom = CustomEqual(3)
actual = {
Expand Down Expand Up @@ -133,6 +145,10 @@ def test_custom_assert_repr_list():
assert str(error) == _expected_warning(actual, expected, "==")


@pytest.mark.skipif(
_low_pytest_version(),
reason="The custom assert_repr is only available in pytest 8 or higher.",
)
def test_custom_assert_repr_list_matcher_replace():
custom = CustomEqual(3)
actual = ["hey", custom]
Expand Down

0 comments on commit f79f5ff

Please sign in to comment.