[lang-ref] ( file_output ) ( python )

def test_file_output(tmp_path):
    # f.write()
    lines = ['test message %03d\n' % x for x in range(5)]
    text  = ''.join(lines)
    p = tmp_path / 'a.txt'

    with p.open('w') as f:
        f.write(text)

    with p.open() as f:
        r = f.read()

    assert r == text
def test_file_output_alternative(tmp_path):
    # f.writelines()
    lines = ['test message %03d\n' % x for x in range(5)]
    text  = ''.join(lines)
    p = tmp_path / 'a.txt'

    with p.open('w') as f:
        f.writelines(lines)

    with p.open() as f:
        r = f.read()

    assert r == text