def testFinalizeChecksForErrors(self):
    mapreduce_state = self.create_mapreduce_state(
        output_params=
        {self.WRITER_CLS.BUCKET_NAME_PARAM: "test"})
    shard_state = self.create_shard_state(0)
    ctx = context.Context(mapreduce_state.mapreduce_spec, shard_state)
    context.Context._set(ctx)

    writer = self.WRITER_CLS.create(mapreduce_state.mapreduce_spec,
                                    shard_state.shard_number, 0)
    writer.begin_slice(None)
    writer.write("foobar")
    # We wrote something, finalize must fail (sanity check).
    self.assertRaises(errors.FailJobError, writer.finalize, ctx, shard_state)
Just make sure finalize is never called after processing data.
dataset/ETHPy150Open GoogleCloudPlatform/appengine-mapreduce/python/test/mapreduce/output_writers_test.py/GCSOutputConsistentOutputWriterTest.testFinalizeChecksForErrors