[lang-ref] ( write_file ) ( python )

def test_write_file(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_write_file_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