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

[Python + Unit Testing] Write Your First Python Unit Test with pytest的更多相关文章

  1. 10 Unit Testing and Automation Tools and Libraries Java Programmers Should Learn

    转自:https://javarevisited.blogspot.com/2018/01/10-unit-testing-and-integration-tools-for-java-program ...

  2. Java Unit Testing - JUnit & TestNG

    转自https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaUnitTesting.html yet another insignifican ...

  3. Live Unit Testing

    Live Unit Testing 相对于传统的Unit Test,VS2017 带来了一个新的功能,叫Live Unit Testing,从字面意思理解就是实时单元测试,在实际的使用中,这个功能就是 ...

  4. C/C++ unit testing tools (39 found)---reference

    http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...

  5. Unit Testing with NSubstitute

    These are the contents of my training session about unit testing, and also have some introductions a ...

  6. [Java Basics3] XML, Unit testing

    What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...

  7. Javascript单元测试Unit Testing之QUnit

    body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; }           QUnit是一个基于JQuery的单元测试Uni ...

  8. [Unit Testing] AngularJS Unit Testing - Karma

    Install Karam: npm install -g karma npm install -g karma-cli Init Karam: karma init First test: 1. A ...

  9. Unit testing Cmockery 简单使用

    /********************************************************************** * Unit testing Cmockery 简单使用 ...

随机推荐

  1. CommonJS,AMD,RequireJS的差别

    RequireJS实现了AMD的API. CommonJS是使用exports对象来定义模块的一种方法,它定义了模块的内容.简单地实现一个CommonJS的定义就像以下这样: // someModul ...

  2. Tween动画TranslateAnimation细节介绍

    Tween动画有下面这几种: Animation   动画 AlphaAnimation 渐变透明度 RotateAnimation 画面旋转 ScaleAnimation 渐变尺寸缩放 Transl ...

  3. 【Swift】学习笔记(六)——函数

    函数  懂编程语言的来说这个是最主要的了,不论什么语言都有函数这个概念.函数就是完毕特定任务的独立代码块. 函数怎么创建: 1.创建一个无參无返回值的函数(实际上全部的函数都有返回值,这个函数返回vo ...

  4. jenkins启动失败

    一:http://localhost:8080已经可以进了 二:修改端口 只是因为8080端口已经有程序占用了,需要修改端口号,但是在jenkins.xml文件中修改端口号,并不起作用. 解决方法是: ...

  5. css sprite的实现

    css sprite 为什么使用css sprite? 网页上的非常多静态小图片在载入时须要大量http请求,添加了响应时间.(哈哈.雅虎34条优化法则的第一条啊) css的background-po ...

  6. C# DispatcherTimer Start之后立即执行

    如果DispatherTimer 的Interval 不是在实例化时赋值,那么Start之后,Tick方法会立即执行一次. DispatcherTimer timer = new Dispatcher ...

  7. 2015.04.30,外语,读书笔记-《Word Power Made Easy》 14 “如何谈论日常现象” SESSION 40

    1. money, and what it will buy penury(['penjuri] n. 贫穷,拮据),来自拉丁词语penuria(need,needness的意思),主要指缺乏财富资源 ...

  8. java1.8对集合中对象的特有属性进行排序

    每天学习一点点,知识财富涨点点 1.创建对象user12 2.编写测试类 3.输出结果 加油!!!!

  9. 微信小程序发送模板消息

    微信小程序发送模板消息 标签(空格分隔): php 看小程序文档 [模板消息文档总览]:https://developers.weixin.qq.com/miniprogram/dev/framewo ...

  10. MSSQL执行大脚本文件时,提示“内存不足”的解决办法

    导出了一个脚本文件,将近900M,回来往sql studio一丢,报了个内存不足,然后就有了此文.. 问题描述: 当客户服务器不允许直接备份时,往往通过导出数据库脚本的方式来部署-还原数据库, 但是当 ...