[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 简单使用 ...
随机推荐
- [using_microsoft_infopath_2010]Chapter8 使用InfoPath表单web部件
本章概要: 1.配置web part 2.创建web part连接 3.创建表单参数 4.利用其它浏览器表单参数
- struts2提交多个对象带图片
一:实体类 二:前台页面 三:Action处理
- 0x27 A*
终于完全了解A*到底是什么玩意儿了 对于当前的决策,选取当前花费+预估花费最小来拓展. 因为假如预估出现失误,那么很可能就会延伸到一个错误的决策点,而这个决策点偏偏就是ed,而由于预估失误,其他点的当 ...
- poj--1236--Network of Schools(scc+缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14062 Accepted: 56 ...
- BZOJ 3105 线性基 高斯消元
思路: 按照从大到小排个序 维护两个数组 一个是消元后的 另一个是 按照消元的位置排的 不断 维护从大到小 (呃具体见代码) //By SiriusRen #include <cstdio> ...
- ASP.NET MVC+Bootstrap分页Helper
<div class="pagination"> <ul> //************分页HTML********* </ul> </d ...
- SpringBoot(九) ElasticSearch 全文检索
ElasticSearch ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用 ...
- mysql5.5碰到的type= MyISAM报错问题
最近把mysql升级到5.5版本,发现type= MyISAM报错,网上查了一下原来MYSQL5.5.x 版本 不支持 TYPE=MyISAM 这样的语句了!!! MYSQL语句写法 TYPE=My ...
- angular自定义指令-directive
Directive究竟是个怎么样的一个东西呢?我个人的理解是这样的:将一段html.js封装在一起,形成一个可复用的独立个体,具体特定的功能.下面我们来详细解读一下Directive的一般性用法. v ...
- RocketMQ学习笔记(12)----RocketMQ的Consumer API简介
由于消息的消费方式有两种,所以两种方式也有不同的API: 1. PushConsumer的配置 1. consumerGroup: 默认值为DEFAULT_CONSUMER,Consumer组名,多个 ...