【问题标题】:Create directory using pytest fixture使用 pytest 夹具创建目录
【发布时间】:2020-10-22 10:23:08
【问题描述】:

我想在新创建的文件夹“/new_folder/”下的“/tmp/”下本地保存我的日志文件所以我所做的是:

subdir = tmpdir.mkdir("new_folder")

subprocess.call("adb pull /SDcard/log/ {}".format(subdir), shell=True)

但函数失败并出现以下错误:TypeError: sequence item 5: expected string, LocalPath found

你能帮我解决这个问题吗

【问题讨论】:

  • 为什么不使用 pytest 的 tmpdir 夹具? docs.pytest.org/en/stable/tmpdir.html
  • 我正在使用它,我做了 tmpdir.mkdir("") 所以他会在 tmpdir 下创建另一个文件夹

标签: python pytest fixtures


【解决方案1】:

mkdir 返回py._path.local.LocalPath 类型的对象。首先将其转换为字符串,如下所示:

subdir = tmpdir.mkdir("new_folder")
subprocess.call("adb pull /SDcard/log/ {}".format(str(subdir)), shell=True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-04
    • 2021-08-11
    • 2020-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    相关资源
    最近更新 更多