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

"From a list of objects, assert on how many objects contain a specific key/value pair" #51

Open
SatheeshJM opened this issue Apr 13, 2019 · 1 comment

Comments

@SatheeshJM
Copy link

Say I have a list

[{"foo" : "bar"}, {"foo: "bar2"}, {"foo" : "bar"},{"random":"1"}]

Is there a way of asserting that the list contains exactly 2 occurrences of {"foo":"bar"}

Can't seem to find anything in the docs.

@sgissinger
Copy link
Contributor

I would do this

items = [{"foo" : "bar"}, {"foo": "bar2"}, {"foo" : "bar"},{"random":"1"}]
search = {"foo" : "bar"}

matches = [x for x in items if x == search]
matches | should.have.length(2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants