'Make sure there can\'t be a TOCTOU issue when creating the file.
See https://github.com/qutebrowser/qutebrowser/issues/942.'

@pytest.mark.usefixtures('reset_standarddir')
@pytest.mark.parametrize('typ', DIR_TYPES)
def test_exists_race_condition(self, mocker, tmpdir, typ):

    (tmpdir / typ).ensure(dir=True)
    m = mocker.patch('qutebrowser.utils.standarddir.os')
    m.makedirs = os.makedirs
    m.sep = os.sep
    m.path.join = os.path.join
    m.path.exists.return_value = False
    m.path.abspath = (lambda x: x)
    args = types.SimpleNamespace(basedir=str(tmpdir))
    standarddir.init(args)
    func = getattr(standarddir, typ)
    func()
