The title pretty much sums it up: I tried to use assertEqual to test a function that returns a generator object, but that results in:
AssertionError: generator object genexpr> at 0x2e70c80> != (1,2,...)
Is there a clever way to do this other than iterating over the function and running assertEqual for each individual output?
assertEqual(tuple(generator_object), (1, 2, ...))
if it's an infinite generator, or you just wish to look at the first n
results for some reason, you can combint this with itertools.islice
assertEqual(tuple(islice(generator_object, n)), (1, 2, ...))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With