Py之pytest-shutil:Python库之pytest-shutil简介、安装、使用方法之详细攻略
生活随笔
收集整理的這篇文章主要介紹了
Py之pytest-shutil:Python库之pytest-shutil简介、安装、使用方法之详细攻略
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Py之pytest-shutil:Python庫之pytest-shutil簡介、安裝、使用方法之詳細攻略
?
?
目錄
pytest-shutil簡介
pytest-shutil安裝
pytest-shutil函數使用
pytest-shutil使用方法
?
?
?
pytest-shutil簡介
? ? 這個庫是一個很好的用于自動測試的Unix shell和環境管理工具包。下面是可用函數的摘要,請查看完整列表的源代碼。
?
?
pytest-shutil安裝
pip install pytest-shutil?
?
pytest-shutil函數使用
import shutil
copy()
功能:復制文件 格式:shutil.copy('來源文件','目標地址') 返回值:復制之后的路徑copy2()
功能:復制文件,保留元數據 格式:shutil.copy2('來源文件','目標地址') 返回值:復制之后的路徑copyfileobj()
將一個文件的內容拷貝的另外一個文件當中 格式:shutil.copyfileobj(open(來源文件,'r'),open('目標文件','w')) 返回值:無copyfile()
功能:將一個文件的內容拷貝的另外一個文件當中 格式:shutil.copyfile(來源文件,目標文件) 返回值:目標文件的路徑copytree()
功能:復制整個文件目錄 格式:shutil.copytree(來源目錄,目標目錄) 返回值:目標目錄的路徑 注意:無論文件夾是否為空,均可以復制,而且會復制文件夾中的所有內容copymode()
功能:拷貝權限copystat()
功能:拷貝元數據(狀態)rmtree()
功能:移除整個目錄,無論是否空 格式:shutil.rmtree(目錄路徑) 返回值:無move()
功能:移動文件或者文件夾 格式:shutil.move(來源地址,目標地址) 返回值:目標地址which()
功能:檢測命令對應的文件路徑 格式:shutil.which(‘命令字符串’) 返回值:命令文件所在位置 注意:window和linux不太一樣。 window的命令都是.exe結尾,linux則不是disk_usage()
功能:檢測磁盤使用信息 格式:disk_usage(‘盤符’) 返回值:元組?
?
?
pytest-shutil使用方法
def test_something(workspace): # Workspaces contain a handle to the path.py path object (see https://pythonhosted.org/path.py) path = workspace.workspace script = path / ‘hello.sh’ script.write_text(‘#!/bin/shn echo hello world!’) # There is a ‘run’ method to execute things relative to the workspace root workspace.run(‘hello.sh’)1、pytest_shutil.env: Shell helpers
| set_env | contextmanager to set env vars |
| unset_env | contextmanager to unset env vars |
| no_env | contextmanager to unset a single env var |
| no_cov | contextmanager to disable coverage in subprocesses |
2、pytest_shutil.cmdline: Command-line helpers
| umask | contextmanager to set the umask |
| chdir | contextmanager to change to a directory |
| TempDir | contextmanager for a temporary directory |
| PrettyFormatter | simple text formatter for drawing title, paragrahs, hrs. |
| copy_files | copy all files from one directory to another |
| getch | cross-platform read of a single character from the screen |
| which | analoge of unix?which |
| get_real_python_executable | find our system Python, useful when running under virtualenv |
3、pytest_shutil.run: Running things in subprocesses
| run | run a command, with options for capturing output, checking return codes. |
| run_as_main | run a function as if it was the system entry point |
| run_module_as_main | run a module as if it was the system entry point |
| run_in_subprocess | run a function in a subprocess |
| run_with_coverage | run a command with coverage enabled |
?
?
總結
以上是生活随笔為你收集整理的Py之pytest-shutil:Python库之pytest-shutil简介、安装、使用方法之详细攻略的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成功解决You are using pi
- 下一篇: Py之ipykernel:Python库