pytest

Creating databases in SQLAlchemy tests with PostgreSQL

ぐ巨炮叔叔 提交于 2020-01-12 05:24:29
问题 I am building a Pyramid web application which is built on the top of SQLAlchemy and solely relies PostgreSQL as its database backend. What would be a way to have the unit tests structure so that Database is built once per test run - not on every test setUp() as this is too slow for a complex application Database tables are (re)created as they would be created in production (e.g. run migrations from Alembic). Any unclean databases are destroyed at the start of the test run. It is possible to

Creating databases in SQLAlchemy tests with PostgreSQL

拜拜、爱过 提交于 2020-01-12 05:24:06
问题 I am building a Pyramid web application which is built on the top of SQLAlchemy and solely relies PostgreSQL as its database backend. What would be a way to have the unit tests structure so that Database is built once per test run - not on every test setUp() as this is too slow for a complex application Database tables are (re)created as they would be created in production (e.g. run migrations from Alembic). Any unclean databases are destroyed at the start of the test run. It is possible to

Output ASCII art to console on succesfull pytest run

馋奶兔 提交于 2020-01-11 10:48:26
问题 I'm using pytest to run tests in Django project. I'm using pytest.ini where DJANGO_SETTINGS_MODULE is defined, so I run tests with just: pytest Now, I want to add some ASCII art to the console output if the test run is successful. I know I can do: pytest && cat ascii_art.txt But I want to hide the ASCII art to config or somewhere else so that I keep running tests with just pytest . I don't see any pytest config option I can use. Any other ideas how this could be done? 回答1: There are lots of

Output ASCII art to console on succesfull pytest run

回眸只為那壹抹淺笑 提交于 2020-01-11 10:48:07
问题 I'm using pytest to run tests in Django project. I'm using pytest.ini where DJANGO_SETTINGS_MODULE is defined, so I run tests with just: pytest Now, I want to add some ASCII art to the console output if the test run is successful. I know I can do: pytest && cat ascii_art.txt But I want to hide the ASCII art to config or somewhere else so that I keep running tests with just pytest . I don't see any pytest config option I can use. Any other ideas how this could be done? 回答1: There are lots of

testing pyqt application - Qwidget: must construct a qapplication before a qwidget

纵然是瞬间 提交于 2020-01-11 07:26:50
问题 I have a pyqt application and like to test scripts for testing this application. I was able to build the qapplication during my standalone testing. Not sure how to create this object while writing my unittestcases using pytest. import sys from PyQt5.QtWidgets import QApplication, QDialog, QGridLayout, QLabel, QLineEdit class Example(QDialog): def __init__(self, *args, **kwargs): super(Example, self).__init__(*args, **kwargs) self.initUI() def initUI(self): grid = QGridLayout(self) a1 = QLabel

print success messages for asserts in python

ε祈祈猫儿з 提交于 2020-01-11 06:56:41
问题 I am using assert in python. Every time an assert fails I get the failure message which I would have put there to be printed. I was wondering if there is a way to print a custom success message when the assert condition passes? I am using py.test framework. for instance: assert self.clnt.stop_io()==1, "IO stop failed" for the above assert I get message "IO stop failed" if assert fails but I am looking to have "IO stop succeeded" if assert passes. something like this: assert self.clnt.stop_io(

Py.test command not found, but library is installed

家住魔仙堡 提交于 2020-01-10 02:29:27
问题 There are already two posts on stack overflow on this topic; however, none of them have resolved or addressed my specific situation. I have installed pytest via pip install pytest . I am able to import the library in Python as well. The problem is that when I try to use the py.test command in Terminal, I get py.test: command not found . Does anyone have any insight as to why I am not able to use the command in the terminal? EDIT: It even shows up as an installed package: $ pip list cycler (0

pytest学习5-mark用例分类

我们两清 提交于 2020-01-08 17:55:03
使用Mark标记测试用例 通过使用pytest.mark你可以轻松地在测试用例上设置元数据。例如, 一些常用的内置标记: skip - 始终跳过该测试用例 skipif - 遇到特定情况跳过该测试用例 xfail - 遇到特定情况,产生一个“期望失败”输出 parametrize - 在同一个测试用例上运行多次调用(译者注: 参数化数据驱动) 创建自定义标记或将标记应用于整个测试类或模块很容易。 文档中包含有关标记的示例,详情可参阅[使用自定义标记。 注意: 标记只对测试用例有效,对fixtures方法无效。 使用mark功能自定义标记功能 在日常测试过程中,有很多测试用例,但只想执行其中的一部分用例,可以使用@pytest.mark.自定义标签功能满足 例如: 如下代码中,设计了5个用例,但只需要执行第一个和第四个用例,可以给第一个和第四个用例加上同样的标签webtest,然后执行pytest -m webtest命令。具体如下: @pytest.mark.webtest def test_mark_1(): print("这是第一个用例") @pytest.mark.me def test_mark_2(): print("这是第2个用例") @pytest.mark.me def test_mark_3(): print("这是第4个用例") @pytest.mark

-Unittest+HTMLTestRunner不能生成报告解决方法

狂风中的少年 提交于 2020-01-08 12:08:31
-Unittest+HTMLTestRunner不能生成报告解决方法 1 、问题现象 在使用HTMLTestRunner 生成测试报告时,出现程序运行不报错,但不能生成报告的情况。 刚开始找了很久没发现问题,后来加上打印信息,发现根本没执行生成报告这部分代码。最后网上找到原因:pycharm 在运行测试用例的时候 默认是以 unittest 框架来运行的,所以不能生成测试报告。 需要设置成不要用unittest框架运行: HTMLTestRunner.pyw文件经过修改的,需要下载:链接:https://pan.baidu.com/s/1BtF4Xus3kecI8qfTAy4z7w 提取码:2gtj #unittest测试框架#pytest比unittest全面一点#导包import requests#导入接口用的包import unittestfrom pyJIAO.APP.APP.aa.baogao4 import Test01from test1.PO3.zhiliao.HTMLTestRunnerNew import HTMLTestRunnerimport timeclass Test(unittest.TestCase): # 用于测试用例执行前的初始化工作 def setUp(self): print("test start") def test_bbb(self):

pytest 运行用例报错:unknown hook 'pytest_namespace' in plugin <module 'allure.pytest_plugin'

点点圈 提交于 2020-01-08 11:06:48
以pytest方式运行用例,报错:pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace' in plugin <module 'allure.pytest_plugin' from 'D:\\python3.7.1\\lib\\site-packages\\allure\\pytest_plugin.py'> 网上说是pytest版本过高了 环境中pytest是5.3.1的,卸载重新安装pytest==4.0.2,可以正常运行 来源: https://www.cnblogs.com/xioawu-blog/p/12038274.html