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

function description
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

function description
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

function description
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简介、安装、使用方法之详细攻略相关推荐

  1. Python语言学习:Python常用自带库(imageio、pickle)简介、使用方法之详细攻略

    Python语言学习:Python常用自带库(imageio.pickle)简介.使用方法之详细攻略 目录 imageio简介及其常见使用方法 pickle简介及其常见使用方法 简介 使用方法 简介及 ...

  2. Python:numpy库中的一些函数简介、使用方法之详细攻略

    Python:numpy库中的一些函数简介.使用方法之详细攻略 目录 numpy库中的一些函数简介.使用方法 1.np.concatenate() 1.1.函数案例 1.2.函数用法 numpy库中的 ...

  3. Py之glob: glob库文件名模式匹配+返回所有匹配的文件路径列表库的简介、使用方法之详细攻略

    Py之glob: glob库文件名模式匹配+返回所有匹配的文件路径列表库的简介.使用方法之详细攻略 目录 glob库的简介 glob库的使用方法 1.单个字符通配符:用问号(?)匹配任何单个的字符.

  4. Python之 sklearn:sklearn中的RobustScaler 函数的简介及使用方法之详细攻略

    Python之 sklearn:sklearn中的RobustScaler 函数的简介及使用方法之详细攻略 目录 sklearn中的RobustScaler 函数的简介及使用方法 sklearn中的R ...

  5. Python编程语言学习:包导入和模块搜索路径简介、使用方法之详细攻略

    Python编程语言学习:包导入和模块搜索路径简介.使用方法之详细攻略 目录 包导入和模块搜索路径简介 1.Pyhon搜索模块路径的机制 2.自定义配置搜索路径

  6. Python之 sklearn:sklearn.preprocessing中的StandardScaler函数的简介及使用方法之详细攻略

    Python之 sklearn:sklearn.preprocessing中的StandardScaler函数的简介及使用方法之详细攻略 目录 sklearn.preprocessing中的Stand ...

  7. Py之matplotlib.pyplot:matplotlib.pyplot的plt.legend函数的简介、使用方法之详细攻略

    Py之matplotlib.pyplot:matplotlib.pyplot的plt.legend函数的简介.使用方法之详细攻略 目录 matplotlib.pyplot的plt.legend函数的简 ...

  8. Python之 sklearn:sklearn中的train_test_split函数的简介及使用方法之详细攻略

    Python之 sklearn:sklearn中的train_test_split函数的简介及使用方法之详细攻略 目录 sklearn中的train_test_split函数的简介 train_tes ...

  9. Py之xlwt:python库之xlwt的简介、安装、使用方法之详细攻略

    导读      xlrd,xlwt和xlutils是用Python处理Excel文档(*.xls)的高效率工具.其中,xlrd只能读取xls,xlwt只能新建xls(不可以修改).       xlu ...

最新文章

  1. 解决 json_encode 中文乱码
  2. 单片机中灯泡显示miss_单片机实例分享,如何设计八路抢答器
  3. 大数据WEB阶段(六)MySql 下载、安装、卸载与配置
  4. ES5和ES6中对于继承的实现方法
  5. 微软:中国市场XP主流支持服务结束时间未定
  6. ddmmyy日期格式是多少_如何在Excel 2013/2016/2019中将mmddyyyy文本转换为普通日期格式...
  7. 苹果x和xs买哪个好_苹果12和苹果11哪个值得买-苹果12和11哪个更值得买
  8. 蓝队应对攻击的常用策略一
  9. iOS 删除本地文件
  10. 自动阅读专业版第七次更新---原薅羊毛专业版
  11. 在Windows 7上面安装Vs2005
  12. 如何在页面上预览word
  13. 【编译原理】第三章语法分析
  14. 宝宝起名神器小程序源码_支持多种流量主模式
  15. wltp和nedc续航差多少_WLTP续航和NEDC续航差多少?
  16. MSTSC 自动登录
  17. wav avi计算机存储音频,把AVI和WAV文件合二为一
  18. Excel模板数据填充导出
  19. 服务器u盘装系统bios设置,服务器bios设置u盘启动
  20. 蓝海卓越 计费管理系统 download.php 任意文件读取漏洞

热门文章

  1. 数据结构-二叉树面试 常考
  2. 一个30岁男人转型码农的平凡之路
  3. 人人都是 API 设计者:我对 RESTful API、GraphQL、RPC API 的思考
  4. 完整的一次 HTTP 请求响应过程(一)
  5. Java微框架Spring Boot 运行原理深入解读
  6. 框架:mybatis常用标签(refid、foreach、trim)
  7. 12:MYSQL 使用函数创建自增序列管理表(批量使用自增表,设置初始值,自增幅度)
  8. Nginx:安装+测试
  9. Vue 之qs 使用详解
  10. 属兔的人今日运势-360星座网_【生肖运势】12月17日