-
Notifications
You must be signed in to change notification settings - Fork 37
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
Multiple image comparison extension types in one test? #687
Comments
@pytest.fixture
def snapshot_image(snapshot):
def _function(image_type):
if image_type == "jpeg":
return snapshot.use_extension(JPEGImageExtension)
if image_type == "png":
return snapshot.use_extension(PNGImageExtension)
raise ValueError("Bad image_type!")
return _function
def test_image_format(snapshot, snapshot_image):
image_data, filename = create_image(0)
filename_extension = filename.split(".")[-1]
assert image_data == snapshot_image(image_type=filename_extension)(name=filename)
image_data, filename = create_image(1)
filename_extension = filename.split(".")[-1]
assert image_data == snapshot_image(image_type=filename_extension)(name=filename) Something like this should work. There might be a way to wrap the snapshot assertion further to have it automatically curry the name parameter. In general, as of this time, Syrupy does not support passing arbitrary parameters to the Snapshot extension class. It's a welcome feature request though. I was actually thinking about it today, since it opens up interesting possibilities for supporting multiple versions of an extension (like multiple serializer versions for the default amber extension). |
Thanks! |
Tracking the "how to pass arbitrary data to a custom extension" as a distinct feature request: #700 |
I'm starting with the example test_custom_image_extension ( https://github.com/tophat/syrupy/blob/main/tests/examples/test_custom_image_extension.py ) and wondering how to extend this to multiple image formats. For example JPEG and PNG.
and then pass both fixtures into the test:
I'm not sure if a snapshot extension can take additional parameters, like the file extension (.jpg, .png) and select the inherited class of SingleFileSnapshotExtension. This would allow us to do something like:
The text was updated successfully, but these errors were encountered: