user1121487
user1121487

Reputation: 2680

Python assertEquals generator

I'm unit testing a generator object that contains objects. I wanna check the objects value property to see if it contains the number, as expected.

The generator object contains 5 object instances from class Test. So I wanna do something like this:

pseudo code: All Test instance object's value property (test.value), in generator object (to list) is equal to [1, 2, 3, 4, 5].

Is this possible to achieve using a one line for loop or something inside the assertEquals method?

Upvotes: 1

Views: 521

Answers (1)

Bill Lynch
Bill Lynch

Reputation: 82006

Since it's only 5 elements, just use a list comprehension.

assertEqual([test.value for test in test_instance_objects], [1, 2, 3, 4, 5])

Upvotes: 1

Related Questions