In this lesson you will create a new project with a virtual environment and write your first unit test with pytest. In doing so, you will learn:

  • install pytest
  • organize your project to support automated test discovery
  • setup Visual Code to use pytest as your test engine
  • best practice naming conventions for tests in Python

Install:

sudo apt install virtualenv

Create virtualenv inside project folder:

virtualenv -p /usr/local/bin/python3 .env

Source to the env:

source .env/bin/activate

Install the lib:

pip install pytest pylint

VSCode workspace settings:

{
"python.pythonPath": "${workspaceFolder}/.env/bin/python",
"python.unitTest.pyTestEnabled": true,
"python.unitTest.pyTestArgs": [
"--ignore=.env",
"-s"
],
"python.envFile": "${workspaceFolder}/.envFile"
}

Code to test:

import pytest
import common_math class TestCommonMath(object): def test_add(self):
result = common_math.add(1,2)
assert result == 3

Testing code:

def add(num1, num2):
return num1 + num2

最新文章

  1. CSS 和 JS 动画哪个更快
  2. Python 3 and MySQL
  3. 运维mysql基础
  4. PHP热身
  5. jquery 温故而知新 Ul 相关的操作
  6. jdownload的使用
  7. ios pyudaren
  8. 【转】Mac 上 java 究竟在哪里,本文彻底让你搞清楚!
  9. java连接数据库的解决方法大全(mysql)
  10. iOS题
  11. Access数据库导入到mysql数据库中
  12. C语言中预定义符 __FILE__, __LINE__, __FUNCTION__, __DATE__, __TIME__ 的使用演示
  13. Android广播——短信拦截
  14. 懵懂oracle之存储过程2
  15. Python爬虫入门:URLError异常处理
  16. 浅析python中socketserver模块使用
  17. python基础之函数式编程
  18. ASP.NET Core入门
  19. python全栈开发day78、79 --bss项目
  20. Extjs4.2 rest 与webapi数据交互----顺便请教了程序员的路该怎么走

热门文章

  1. pythonWeb -- Django开发- Admin
  2. hdoj 5092 Seam Carving 【树塔DP变形 + 路径输出】 【简单题】
  3. UML中的序列图(时序图)
  4. Cocos2d-x学习资源集锦+有奖抽楼活动
  5. 《大话操作系统——做坚实的project实践派》(2)
  6. 初识ecside
  7. mysqli一些常用方法及详解
  8. NEUOJ 1702 撩妹全靠魅力值 (三维偏序)
  9. 院校-美国:美国国立卫生研究院(NIH)
  10. TLP电源管理