首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >测试开发进阶-1.基本环境介绍

测试开发进阶-1.基本环境介绍

作者头像
ITester软件测试小栈
发布2019-11-14 17:05:59
4020
发布2019-11-14 17:05:59
举报
文章被收录于专栏:全栈测试全栈测试全栈测试

虚拟环境

安装

$ pip install virtualenv
$ pip install virtualenvwrapper-win # windows下的管理工具
$ pip install virtualenvwrapper
$ pip install pipenv

查看已安装的虚拟环境

$ workon 

Windows修改安装的位置

新增环境变量

  • 变量名:WORKON_HOME
  • 变量值:虚拟环境存放路径

Linux修改安装的位置

# pip后建立软连接
$ ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv

# Linux配置虚拟环境路径
$ vim ~/.bashrc
# mac配置
$ vim ~/.bash_profile

# 新增
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
export WORKON_HOME=$HOME/.virtualenvs

source /usr/local/python3/bin/virtualenvwrapper.sh

# 执行命令,让配置生效
# Linux
source ~/.bashrc
# mac
source ~/.bash_profile

创建虚拟环境

-p指定解释器

$ mkvirtualenv -p python3 test_py3

进入虚拟环境

$ workon test_py3

退出虚拟环境

$ deactivate

删除虚拟环境

$ rmvirtualenv test_py3

导出虚拟环境中所有的模块和包

$ pip frezz >requirements.txt

安装requirements.txt中的包

$ pip install -r requirements.txt

virtualenv存在的问题

virtualenv卸载一个包之后,相关依赖不会被同步卸载

pipenv

与项目绑定

创建虚拟环境

$ pipenv install

进入虚拟环境

$ pipenv shell

退出虚拟环境

exit

安装包

在哪个路径下操作,就安装到哪个环境

$ pipenv install requests

查看依赖

$ pipenv graph

卸载包

当前环境的依赖不会被卸载

移植PipfilePipfile.lock后重新生成不会携带

$ pipenv uninstall requests

开发环境安装

$ pipenv install --dev requests

导出包

$ pipenv lock -r >requirements.txt

删除虚拟环境

PipfilePipfile.lock不会被删除

$ pipenv --rm

编码规范

python之禅 import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!

缩进

  • 每一级缩进使用4个空格
# 左对齐
foo = long_function_name(var_one, var_two,
                         var_three, var_four)
# 换行缩进
foo = long_function_name(
   var_one, var_two,
   var_three, var_four)

# 用更多的缩进来与其他行区分
foo = long_function_name(
   var_one, var_two, var_three,
   var_four)

行的最大长度

  • 最大79
  • 注释最大72

空行

  • 函数之间2个空行
  • 类的方法之间1个空行

注释

  • 块注释

与代码在同一行

  • 行内注释
  • 文档注释

第一行:对函数/类整体功能说明 参数说明 :param var_one: 参数1 是干嘛的 :type var_one:int 返回值说明 :return:

PEP257:https://github.com/qiuxiang/pep/blob/master/peps/257.md

模块包导入

  • 先导入python内置模块和包
  • 导入第三方的模块和包
  • 导入自定义的模块和包

__all__=[] 使用*导入时候只会导入all的[]中的的内容

结构化工程

https://pythonguidecn.readthedocs.io/zh/latest/writing/structure.html

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-11-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 ITester软件测试小栈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 虚拟环境
    • 安装
      • 查看已安装的虚拟环境
        • Windows修改安装的位置
          • Linux修改安装的位置
            • 创建虚拟环境
              • 进入虚拟环境
                • 退出虚拟环境
                  • 删除虚拟环境
                    • 导出虚拟环境中所有的模块和包
                      • 安装requirements.txt中的包
                        • virtualenv存在的问题
                        • pipenv
                          • 创建虚拟环境
                            • 进入虚拟环境
                              • 退出虚拟环境
                                • 安装包
                                  • 查看依赖
                                    • 卸载包
                                      • 开发环境安装
                                        • 导出包
                                          • 删除虚拟环境
                                          • 编码规范
                                            • 缩进
                                              • 行的最大长度
                                                • 空行
                                                  • 注释
                                                    • 模块包导入
                                                    • 结构化工程
                                                    领券
                                                    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档