当前位置: 首页 > news >正文

什么是网站网页主页敬请期待下一句怎么对

什么是网站网页主页,敬请期待下一句怎么对,网站建设花多少钱,网站建设的硬件平台1. 相关的fixture 1.1. tmp_path1.2. tmp_path_factory1.3. tmpdir1.4. tmpdir_factory1.5. 区别 2. 默认的基本临时目录 1. 相关的fixture 1.1. tmp_path tmp_path是一个用例级别的fixture#xff0c;其作用是返回一个唯一的临时目录对象#xff08;pathlib.Path#xf…1. 相关的fixture 1.1. tmp_path1.2. tmp_path_factory1.3. tmpdir1.4. tmpdir_factory1.5. 区别 2. 默认的基本临时目录 1. 相关的fixture 1.1. tmp_path tmp_path是一个用例级别的fixture其作用是返回一个唯一的临时目录对象pathlib.Path 我们看下面的例子 # src/chapter-6/test_tmp_path.pyCONTENT contentdef test_create_file(tmp_path):d tmp_path / sub d.mkdir() # 创建一个子目录p d / hello.txtp.write_text(CONTENT)assert p.read_text() CONTENTassert len(list(tmp_path.iterdir())) 1 # iterdir() 迭代目录返回迭代器assert 0 # 为了展示强制置为失败执行 λ pytest -q -s src/chapter-6/test_tmp_path.py FFAILURES ________________________________ test_create_file _________________________________tmp_path WindowsPath(C:/Users/luyao/AppData/Local/Temp/pytest-of-luyao/pytest-4/test_create_file0)def test_create_file(tmp_path):d tmp_path / subd.mkdir() # 创建一个子目录p d / hello.txtp.write_text(CONTENT)assert p.read_text() CONTENTassert len(list(tmp_path.iterdir())) 1 # iterdir() 迭代目录返回迭代器assert 0 # 为了展示强制置为失败 E assert 0src\chapter-6\test_tmp_path.py:32: AssertionError 1 failed in 0.06s可以看出 tmp_path在不同的操作系统中返回的是不同类型的pathlib.Path对象这里Windows系统下返回的是WindowsPath对象它是Path的子类对象Path对象可以使用/操作符代替常用的os.path.join()的方法更多关于pathlib的使用方法可以查看https://docs.python.org/3.7/library/pathlib.html 1.2. tmp_path_factory tmp_path_factory是一个会话级别的fixture其作用是在其它fixture或者用例中创建任意的临时目录 查看上一章tmp_path fixture的源码我们能够看到tmp_path就是使用tmp_path_factory的一个例子 # _pytest.tmpdirpytest.fixture def tmp_path(request, tmp_path_factory):Return a temporary directory path objectwhich is unique to each test function invocation,created as a sub directory of the base temporarydirectory. The returned object is a :class:pathlib.Pathobject... note::in python 3.6 this is a pathlib2.Pathreturn _mk_tmp(request, tmp_path_factory)pytest.fixture(scopesession) def tmp_path_factory(request):Return a :class:_pytest.tmpdir.TempPathFactory instance for the test session.return request.config._tmp_path_factory可以看出 tmp_path调用了tmp_path_factory tmp_path_factory返回一个_pytest.tmpdir.TempPathFactory对象 进一步查看_mk_tmp的源码 def _mk_tmp(request, factory):name request.node.namename re.sub(r[\W], _, name)MAXVAL 30name name[:MAXVAL]return factory.mktemp(name, numberedTrue)可以看出tmp_path最终调用了TempPathFactory.mktemp()方法它返回的是一个pathlib.Path对象 1.3. tmpdir tmp_path是一个用例级别的fixture其作用是返回一个唯一的临时目录对象py.path.local它提供os.path的方法 上面的例子也可以修改成如下这样 # src/chapter-6/test_tmpdir.pyCONTENT contentdef test_create_file(tmpdir):p tmpdir.mkdir(sub).join(hello.txt) # 创建子文件夹并新建文件p.write(CONTENT)assert p.read() CONTENTassert len(tmpdir.listdir()) 1 # iterdir() 迭代目录返回列表assert 0 # 为了展示强制置为失败执行 λ pytest -q -s src/chapter-6/test_tmpdir.py FFAILURES ________________________________ test_create_file _________________________________ tmpdir local(C:\\Users\\luyao\\AppData\\Local\\Temp\\pytest-of-luyao\\pytest-6\\test_create_file0)def test_create_file(tmpdir):p tmpdir.mkdir(sub).join(hello.txt) # 创建子文件夹并新建文件p.write(CONTENT)assert p.read() CONTENTassert len(tmpdir.listdir()) 1 # iterdir() 迭代目录返回列表assert 0 # 为了展示强制置为失败 E assert 0src\chapter-6\test_tmpdir.py:30: AssertionError 1 failed in 0.06s其实tmpdir也调用了tmp_path只是对返回值做了一次py.path.local()封装 # _pytest.tmpdirpytest.fixture def tmpdir(tmp_path):Return a temporary directory path objectwhich is unique to each test function invocation,created as a sub directory of the base temporarydirectory. The returned object is a py.path.local_path object... _py.path.local: https://py.readthedocs.io/en/latest/path.htmlreturn py.path.local(tmp_path)1.4. tmpdir_factory tmpdir_factory是一个会话级别的fixture其作用是在其它fixture或者用例中创建任意的临时目录 假设一个测试会话需要使用到一个很大的由程序生成的图像文件相比于每个测试用例生成一次文件更好的做法是每个会话只生成一次 import pytestpytest.fixture(scopesession) def image_file(tmpdir_factory):img compute_expensive_image()fn tmpdir_factory.mktemp(data).join(img.png)img.save(str(fn))return fndef test_histogram(image_file):img load_image(image_file)# compute and test histogram1.5. 区别 fixture作用域返回值类型tmp_path用例级别functionpathlib.Pathtmp_path_factory会话级别sessionTempPathFactorytmpdir用例级别functionpy.local.pathtmpdir_factory会话级别sessionTempDirFactory 2. 默认的基本临时目录 上述fixture在创建临时目录时都是创建在系统默认的临时目录例如Windows系统的%temp%目录下你可以通过指定--basetempmydir选项自定义默认的基本临时目录 λ pytest -q -s --basetemp/d/temp src/chapter-6/test_tmpdir.py FFAILURES ________________________________ test_create_file _________________________________ tmpdir local(D:\\temp\\test_create_file0)def test_create_file(tmpdir):p tmpdir.mkdir(sub).join(hello.txt) # 创建子文件夹并新建文件p.write(CONTENT)assert p.read() CONTENTassert len(tmpdir.listdir()) 1 # iterdir() 迭代目录返回列表assert 0 # 为了展示强制置为失败 E assert 0src\chapter-6\test_tmpdir.py:30: AssertionError 1 failed in 0.04s
http://www.pierceye.com/news/997538/

相关文章:

  • 自己做的网站怎么添加采集模块网站管理包括哪些内容
  • php做网站验证码的设计电商网站的二级怎么做
  • 广西网站建设价钱微信crm管理系统
  • 福州网站建设公司中小企业荆门市城乡建设管理局网站
  • 建设信用卡网站首页有做车身拉花的网站吗
  • 怎么做婚恋网站织梦网站推广插件
  • rtt全民互助平台网站开发自己怎样做免费网站
  • 建站模板东营建网站公司
  • 如何用vs做网站网络推广方案下拉管家微xiala11
  • 可以做彩票广告的网站吗做网站的应用
  • 龙岗网站 建设深圳信科湘潭做网站价格品牌磐石网络
  • 湖北网站排名优化安卓项目开发
  • 网站怎么引入微信支付郑州官方通报
  • 在南宁做家教兼职的网站北京通州做网站
  • 深圳网站的建设维护公司秦皇岛市建设局官网
  • 做网站 插件静态网站开发课程相关新闻
  • 网站建站 公司无锡搜索引擎营销的内容
  • 公司网站建设小知识单页网站是什么样子的
  • 大学网站建设排名深圳网站建设公司报价
  • 贵阳网站制作公司茶叶推广方案
  • 自适应 网站开发wordpress域名邮箱设置
  • 深圳网站设计网站制作非织梦做的网站能仿吗
  • 做网站可以使用免费空间吗沧州百姓网免费发布信息网
  • 关于阅读类网站的建设规划书使用密码访问wordpress文章
  • 做鲜花配送网站需要准备什么郑州官网网站优化公司
  • 评论网站建设个人网站域名名字
  • 郑州做茶叶的网站科技公司官网设计源代码
  • 武夷山住房和城乡建设部网站广东建设报网站
  • 怎样建设网站是什么样的免费软件不收费网站
  • 网站服务器如何管理seo知名公司