Search code examples
pythonpytestfixtures

Create directory using pytest fixture


I want to save my log files locally under '/tmp/' under a new created folder '/new_folder/' So what i did is :

subdir = tmpdir.mkdir("new_folder")

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

But the function fails with this error : TypeError: sequence item 5: expected string, LocalPath found

Could you please help me to fix this issue


Solution

  • mkdir returns object of the type py._path.local.LocalPath. Convert it to string first like this:

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