Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Recommended way of testing app using Pillow #8945

Answered by radarhere
js-compilatrum asked this question in Q&A
Discussion options

I browse official tests:
https://github.com/python-pillow/Pillow/tree/main/Tests

to get general idea and I have questions:

How are you testing your Pillow scripts apps?
Can you share any advices to construct app correctly?

I am creating project with massive image generation for weather station and I want simply create tests (I prefer pytest) to be sure when I change one part it is not messes another. I am looking ideas how do it correctly as I don't have experience with scripts which drawing. My first thought is create display image as matrix which is 16-color grayscale and using 1/0 match drawed part and based on this create all tests suite using methid get_pixel, but it seems complicated and it is needed extra boilerplate.

You must be logged in to vote

Hi. As you have probably gathered, our Tests directory uses pytest. It is for testing that Pillow behaves as expected. You can read more about how to run our test suite at https://github.com/python-pillow/Pillow/blob/main/Tests/README.rst

Can you share any advices to construct app correctly?

You might be interested in a discussion where another user has shared their application - #8561

My first thought is create display image as matrix which is 16-color grayscale and using 1/0 match drawed part and based on this create all tests suite using methid get_pixel, but it seems complicated and it is needed extra boilerplate.

It sounds like you're describing

from PIL import Image
im = Image.new(

Replies: 1 comment

Comment options

Hi. As you have probably gathered, our Tests directory uses pytest. It is for testing that Pillow behaves as expected. You can read more about how to run our test suite at https://github.com/python-pillow/Pillow/blob/main/Tests/README.rst

Can you share any advices to construct app correctly?

You might be interested in a discussion where another user has shared their application - #8561

My first thought is create display image as matrix which is 16-color grayscale and using 1/0 match drawed part and based on this create all tests suite using methid get_pixel, but it seems complicated and it is needed extra boilerplate.

It sounds like you're describing

from PIL import Image
im = Image.new("RGB", (100, 100))
expected = Image.new("RGB", (100, 100))
for x in range(im.width):
 for y in range(im.height):
 assert im.getpixel((x, y)) == expected.getpixel((x, y))

You may find using tobytes() simpler.

from PIL import Image
im = Image.new("RGB", (100, 100))
expected = Image.new("RGB", (100, 100))
assert im.tobytes() == expected.tobytes()

An example of this in our test suite is at

Pillow/Tests/helper.py

Lines 84 to 87 in 07df26a

def assert_image_equal(a: Image.Image, b: Image.Image, msg: str | None = None) -> 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)}"
if a.tobytes() != b.tobytes():
You must be logged in to vote
0 replies
Answer selected by radarhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /