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. Android菜鸟笔记- 获取未安装的APK图标、版本号、包名、名称、是否安装、安装、打开

    周末闲来无事,把Android的基础知识拿出来复习复习,今天主题是<获取未安装的APK图标.版本号.包名.名称.是否安装.跳转安装.打开> 一.获取APK图标 通常读取APK的图标能够用, ...

  2. Ubuntu下的用户和权限(三)

    七.增删群组相关的命令 相同的我们要先介绍两个重要的设定档:/etc/group和/etc/gshadow,前面那个事实上和/etc/passwd一样.而后者就是群组的password表了.先看看长啥 ...

  3. Codeforces Round #338 (Div. 2) B. Longtail Hedgehog 记忆化搜索/树DP

    B. Longtail Hedgehog   This Christmas Santa gave Masha a magic picture and a pencil. The picture con ...

  4. 错误 'Cannot run program "/home/uv/IDE/adt/sdk/platform-tools/adb": error=2, No such file or directory

    转 Linux下Android SDK中adb找不到的解决方案 2013年04月22日 20:41:48 阅读数:7621 在Linux平台下配置Android SDK开发环境过程中,Eclipse会 ...

  5. linux下的静态库创建与查看,及如何查看某个可执行依赖于哪些动态库

    linux下的静态库创建与查看,及如何查看某个可执行依赖于哪些动态库   创建静态库:ar -rcs test.a *.o查看静态库:ar -tv test.a解压静态库:ar -x test.a 查 ...

  6. iis browse的时候,直接通过本地的局域网ip打开页面

    http://www.codepal.co.uk/show/make_IIS_work_with_local_IP_addresses_instead_of_localhost 只需要设置一下webs ...

  7. 通过QEMU-GuestAgent实现从外部注入写文件到KVM虚拟机内部

    本文将以宿主上直接写文件到VM内部为例讲解为何要注入以及如何实现 tag: qemu-ga, qemu guest agent, kvm, guest-file-write, inject 小慢哥的原 ...

  8. Vmware 安装虚拟工具 (二)

    打开虚拟机,以root超级用户登陆,菜单栏选择虚拟机,install安装虚拟机 拷贝虚拟工具到 在根目录下建立文件夹,并将工具拷贝到该文件夹,例如vmtool 打开终端,进入该目录开始安装 如图,进入 ...

  9. (转)用Lottie制作动画,我的月薪翻了一番!!

    Lottie是Airbnb发布的开源动画库. 帮助动效落地.学会使用Lottie,会极大地提高工作效率. Lottie是一种新的开发动画的方式. 学会使用Lottie,会极大改善你和开发小哥哥撕逼的情 ...

  10. Oracle学习系类篇(二)

    1.Oracle对表的增删改 1.1添加列 1.2修改列 1.3 删除列 1.4 修改表名称 1.5 修改列名称 1.6 删除主键约束 1.7 添加主键约束 1.8 添加外键约束