From 56680b253c681601692a1b215e1b8ed846469923 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 3 Jan 2023 00:23:45 -0600 Subject: [PATCH] set verbosity to 0 before comparing image bytes --- Tests/helper.py | 8 ++++++++ conftest.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/Tests/helper.py b/Tests/helper.py index fd97a5614..640e9b5d2 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -15,6 +15,9 @@ from packaging.version import parse as parse_version from PIL import Image, ImageMath, features +# overridden in conftest.py +pytestconfig = {"option": {"verbose": 0}} + logger = logging.getLogger(__name__) @@ -88,7 +91,10 @@ def assert_image_equal(a, b, msg=None): assert a.mode == b.mode, msg or f"got mode {repr(a.mode)}, expected {repr(b.mode)}" assert a.size == b.size, msg or f"got size {repr(a.size)}, expected {repr(b.size)}" + original_verbosity = pytestconfig.option.verbose try: + # set pytest's verbosity to 0 so that it doesn't show the full bytes diff + pytestconfig.option.verbose = 0 assert a.tobytes() == b.tobytes(), msg or "got different content" except AssertionError: if HAS_UPLOADER: @@ -99,6 +105,8 @@ def assert_image_equal(a, b, msg=None): pass raise + finally: + pytestconfig.option.verbose = original_verbosity def assert_image_equal_tofile(a, filename, msg=None, mode=None): diff --git a/conftest.py b/conftest.py index e123cca80..3eccf131f 100644 --- a/conftest.py +++ b/conftest.py @@ -1 +1,12 @@ pytest_plugins = ["Tests.helper"] + + +def pytest_configure(config): + """ + Keep a reference to pytest's configuration in our helper class. + This function is called by pytest each time the configuration is updated. + https://docs.pytest.org/en/latest/reference/reference.html#pytest.hookspec.pytest_configure + """ + import Tests.helper + + Tests.helper.pytestconfig = config