Skip to content

Conversation

@radarhere
Copy link
Member

At the start of test_file_jpeg2k.py, an image is opened.

test_card = Image.open("Tests/images/test-card.png")
test_card.load()

It is then used throughout the tests.

def test_lossless_rt() -> None:
im = roundtrip(test_card)
assert_image_equal(im, test_card)
def test_lossy_rt() -> None:
im = roundtrip(test_card, quality_layers=[20])
assert_image_similar(im, test_card, 2.0)

Rather than re-using the same image instance throughout the tests, and allowing it to be potentially modified in one test and affect all subsequent tests, this PR uses a fixture to re-open it each time, following the style of test_image_resize.py.

test_card.load()

@pytest.fixture
def test_card() -> Generator[ImageFile.ImageFile, None, None]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

I know the old one was also prefixed test_, but that makes it look like a test function. Maybe just card?

Suggested change
def test_card() -> Generator[ImageFile.ImageFile, None, None]:
def card() -> Generator[ImageFile.ImageFile, None, None]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've pushed a commit.

@radarhere radarhere merged commit 1654eea into python-pillow:main Oct 26, 2024
43 checks passed
@radarhere radarhere deleted the fixture branch October 26, 2024 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants