def METHOD_NAME(self, monkeypatch, args, expected, stat_exists):
    makedirs = {'called': False}
    def mock_mkdtemp(prefix, dir):
        return os.path.join(dir, prefix)
    def mock_makedirs(path, mode):
        makedirs['called'] = True
        makedirs['path'] = path
        makedirs['mode'] = mode
        return
    monkeypatch.setattr(tempfile, 'mkdtemp', mock_mkdtemp)
    monkeypatch.setattr(os.path, 'exists', lambda x: stat_exists)
    monkeypatch.setattr(os, 'makedirs', mock_makedirs)
    monkeypatch.setattr(shutil, 'rmtree', lambda x: None)
    monkeypatch.setattr(basic, '_ANSIBLE_ARGS', to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args})))
    with patch('time.time', return_value=42):
        am = basic.AnsibleModule(argument_spec={})
        actual_tmpdir = am.tmpdir
    assert actual_tmpdir == expected
    # verify subsequent calls always produces the same tmpdir
    assert am.tmpdir == actual_tmpdir
    if not stat_exists:
        assert makedirs['called']
        expected = os.path.expanduser(os.path.expandvars(am._remote_tmp))
        assert makedirs['path'] == expected
        assert makedirs['mode'] == 0o700