Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fixture to re-open image for each JPEG2000 test #8484

Merged
merged 2 commits into from
Oct 26, 2024

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
46 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants