def METHOD_NAME(tmpdir_factory, nwbfile):
    out_path = os.path.join(
        str(tmpdir_factory.mktemp("test_serialize")),
        "out.nwb"
    )
    sink = nwb2_sink.Nwb2Sink(None)
    sink._data = io.BytesIO()
    sink._h5_file = h5py.File(sink._data, "w")
    sink._nwb_io = pynwb.NWBHDF5IO(
        path=sink._h5_file.filename,
        mode="w",
        file=sink._h5_file
    )
    sink.nwbfile = nwbfile
    sink.serialize({"output_path": out_path})
    with pynwb.NWBHDF5IO(out_path, "r", load_namespaces=True) as reader:
        obt = reader.read()
        assert obt.identifier == "test session"