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

[BUG] Error with array inputs to test method #82

Open
lenabradley opened this issue Feb 23, 2021 · 1 comment · Fixed by #96
Open

[BUG] Error with array inputs to test method #82

lenabradley opened this issue Feb 23, 2021 · 1 comment · Fixed by #96
Assignees
Labels
bug Something isn't working

Comments

@lenabradley
Copy link
Contributor

lenabradley commented Feb 23, 2021

Describe the bug
When test method argument values (e.g. for parameterized inputs) are arrays, the snapshot lookup fails.

Error:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Note: I believe this would also occur with other complex argument types, such as pandas dataframes.

To Reproduce

import pytest
import numpy as np

@pytest.mark.parametrize("my_array", [np.array([-1.0, 0.0, 1.0])])
def test_something(snapshot, my_array):
    """Test with array input argument"""
    snapshot.assert_match(5)

This fails on snapshot lookup, so fails on running the test for the 2nd+ time (after snapshot creation).

Error trace:

self = <snappiershot.snapshot.metadata.SnapshotMetadata object at 0x13287b250>
metadata_dict = {'arguments': {'my_array': [-1.0, 0.0, 1.0]}, 'test_runner_provided_name': '', 'update_on_next_run': False, 'user_provided_name': ''}

    def matches(self, metadata_dict: Dict) -> bool:
        """ Check if the "metadata" section of a snapshot file sufficiently matches
        this metadata object.
    
        This matching is used to identify snapshots of tests within a snapshot file.
    
        Args:
            metadata_dict: The "metadata" section to compare against this object.
        """
>       return self.caller_info.args == metadata_dict["arguments"]
E       ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Expected behavior
No failure; correct lookup of associated snapshot

Screenshots
N/A

Versions:

  • Python version:
  • Snappiershot version:

Additional context
Add any other context about the problem here.

@lenabradley lenabradley added the bug Something isn't working label Feb 23, 2021
@lenabradley lenabradley changed the title [BUG] Error with sequnce inputs to test method [BUG] Error with array inputs to test method Feb 23, 2021
@bbonenfant
Copy link
Contributor

This is an issue with the test function arguments within the metadata needing to be passed through the default_encode_value utility method. This should be relatively straightforward to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants