3 ms·
I don't fully disagree, but the yield context manager approach is very common when writing test fixtures, you do: # setup yield resource. # teardown
by mpeg 1y ago
I don't fully disagree, but the yield context manager approach is very common when writing test fixtures, you do:
# setup
yield resource.
# teardown
Not that it makes it any less magical, but at least it's a consistent python pattern
- red_admiral 1y agoTest fixtures as opposed to production code forgive a multitude of sins. Sometimes you have to mock up an object that could never exist in the real world, to assert that the main code doesn't just accept it and move on. Sometimes you poke at individual variables in an object that in the real world should only be accessed via the methods in its API. All in a day's work if you know what you're doing and never try that in the real code.