zoukankan      html  css  js  c++  java
  • Python_任意文件中获取项目的绝对路径

    使用HTMLTestRunner.py(Version 0.8.2.2-huanghe)时,遇到添加饼图的问题,由于原HTMLTestRunner_my.py文件是适配任意场景的,所以饼图这个函数DrawPie(self, result)的896行:

    firedir = r'%s/myreports/mypies/'%os.path.dirname(os.path.abspath(__file__)) 

    如果把HTMLTestRunner.py与放置饼图的目录分开存放,就会在运行主程序时遇到找不到pie.png问题。

    为了解决这问题,需要处理2个点:

    1、要知道项目根目录是什么,当然不能写死了,万一更换位置部署程序,就会出错。

    1 project_name = "InterfaceTest_project"
    2 curPath = os.path.abspath(os.path.dirname(__file__))
    3 rootPath = curPath[:curPath.find(project_name+"\")+len(project_name+"\")]  #关键点!!

    此时获取的内容是e:abccd这样的路径,print看到的是e:\abc\bcd\

    2、需要把获取到项目根路径中“”(用print看到的是"\")替换测“/”。

    1 rootPath = str(rootPath).replace("\","/")
    2 firedir='{}reports/mypies'.format(rootPath) #饼图存储的目录
    3 # 这里与HTMLTestRunner.py原代码firedir='%s/myreports/mypies'%rootpath不太一样,
    4 #用的时候自己修改一下就行
  • 相关阅读:
    jdk8 xp
    electron react
    electron install失败
    0511 Braft Editor和嵌套路由
    组播
    0427
    duilib自定义组件
    android 读写文件、列出根目录文件及新版本权限
    android Fragment使用RecyclerView
    Duilib 带xml的1
  • 原文地址:https://www.cnblogs.com/kuzaman/p/11528812.html
Copyright © 2011-2022 走看看