[Python + Unit Testing] Write Your First Python Unit Test with pytest
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的更多相关文章
- 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 ...
- Java Unit Testing - JUnit & TestNG
转自https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaUnitTesting.html yet another insignifican ...
- Live Unit Testing
Live Unit Testing 相对于传统的Unit Test,VS2017 带来了一个新的功能,叫Live Unit Testing,从字面意思理解就是实时单元测试,在实际的使用中,这个功能就是 ...
- C/C++ unit testing tools (39 found)---reference
http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...
- Unit Testing with NSubstitute
These are the contents of my training session about unit testing, and also have some introductions a ...
- [Java Basics3] XML, Unit testing
What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...
- Javascript单元测试Unit Testing之QUnit
body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; } QUnit是一个基于JQuery的单元测试Uni ...
- [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 ...
- Unit testing Cmockery 简单使用
/********************************************************************** * Unit testing Cmockery 简单使用 ...
随机推荐
- [Beginning SharePoint Designer 2010]探索SharePoint Designer
本章概要: 1.SharePoint Designer是如何进入到微软的工具集中去的 2.SharePoint Designer的基本特性 3.如何创建SharePoint站点 4.如何打开一个已经存 ...
- Atom介绍和安装步骤
Atom是全然基于web技术开发而成的一款编辑器,其底层架构依赖于chromium,google chrome浏览器也是基于此.编辑器的每一个窗体都是本地渲染的web页面,而且其风格与时下流行的sub ...
- hdu2688 Rotate(树状数组)
题目链接:pid=2688">点击打开链接 题意描写叙述:对一个长度为2<=n<=3000000的数组,求数组中有序对(i<j而且F[i]<F[j])的数量?其 ...
- 简单的Queue
不考虑好多东西,算法考试中用得到的Queue #include<iostream> using namespace std; const int MAX = 100; struct MyQ ...
- 编译Redis系统提示缺少gcc,可以使用yum进行安装:
yum -y install gcc yum -y install gcc-c++ yum install make -- 或者 yum groupinstall "Development ...
- oracle手工生成AWR报告方法
AWR(Automatic Workload Repository)报告是我们进行日常数据库性能评定.问题SQL发现的重要手段.熟练掌握AWR报告,是做好开发.运维DBA工作的重要基本功. AWR报告 ...
- Bata版本
一.团队成员 1)冯鹏(组长) 201731062617 2)鲜泽 201731062612 3)李家豪 201731062614 4)郭经伟 201731062615 5)程前勇 2017310 ...
- BZOJ 1806 DP
思路: f[i][a][b][c][d] 表示在第i天 昨天1矿吃的是a 前天1矿吃的是b 昨天2矿吃的是c 前天2矿吃的是d 的最优解 暴力转移 哦 需要优化一下空间- 变成i%2 就好了 //By ...
- VB.net 捕获项目全局异常
在项目中添加如下代码:新建窗口来显示异常信息. Namespace My '全局错误处理,新的解决方案直接添加本ApplicationEvents.vb 到工程即可 '添加后还需要一个From用来显示 ...
- Neo4j下执行cypher-shell时,Connection refused问题解决?
不多说,直接上干货! 问题现象 root@zhouls-/bin# ls cypher-shell neo4j neo4j-admin neo4j-import neo4j-shell tools ...