pytest

Pytest logging ignores options in pytest.ini

一世执手 提交于 2020-01-04 03:58:08
问题 I have a test that I am running with: pytest --capture=no --verbose --rootdir=testing/ testing/tests/docker_test.py from /home/user/development/ . The test checks if some containers are running and uses the default logging framework of Python 3.6. The logger inside the test file is configured as follows: logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) logging.basicConfig(level=logging.INFO, stream=sys.stdout, format="%(asctime)s %(levelname)s %(message)s") Inside tests I am

Using Command Line Parameters with pytest --pyargs

拟墨画扇 提交于 2020-01-03 20:22:45
问题 I have written pytest unit tests for a package I've written with a structure like below: packagedir setup.py mypackage __init__.py functionpackage __init__.py functionmodule.py test __init__.py conftest.py unit_tests __init__.py functionmodule_test.py Now packagedir/mypackage/test/conftest.py establishes two required command line parameters to be created as fixtures for the tests. When I run something like: pytest packagedir/mypackage/ --var1 foo --var2 bar All the tests run and the command

pycharm中使用allure报AttributeError: module 'pytest' has no attribute 'allure'错误

余生颓废 提交于 2020-01-03 17:40:17
原因可能由于:因为pytest-allure-adaptor库基本被python3放弃了,运行很不友好,所以报错 解决方法: terminal中先卸载:pip uninstall pytest-allure-adaptor 再安装:pip allure-pytest 若安装找不到该模块可以去设置那下载 来源: CSDN 作者: xiao_feng77 链接: https://blog.csdn.net/xiao_feng77/article/details/103820687

Using Ansible variables in testinfra

泪湿孤枕 提交于 2020-01-03 17:16:57
问题 Using TestInfra with Ansible backend for testing purposes. Everything goes fine except using Ansible itself while running tests test.py import pytest def test_zabbix_agent_package(host): package = host.package("zabbix-agent") assert package.is_installed package_version = host.ansible("debug", "msg={{ zabbix_agent_version }}")["msg"] (...) where zabbix_agent_version is an Ansible variable from group_vars. It can be obtained by running this playbook - hosts: all become: true tasks: - name:

sys.path including py.test rootdir to make tests import relative to project root

做~自己de王妃 提交于 2020-01-03 15:36:02
问题 I'm having problems with pytest not including my projects rootdir in sys.path list. Instead it is including the directory where the tests are located by default. Here is my project structure. proj/ setup.py mypackage/ __init__.py a.py tests/ test_a.py when running pytest with py.test proj/mypackage/tests it inserts proj/mypackage/tests into sys.path which is not good because now I cannot import a since its not relative to the tests directory. I've noticed that py.test detects a rootdir, this

Django: using same test database in a separate thread

做~自己de王妃 提交于 2020-01-03 09:02:14
问题 I am running pytests using a test database with the following DB settings. DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'something', 'PASSWORD': 'password', }, } Using the @pytest.mark.django_db, my test functions access a database called 'test_postgres' created for the tests. @pytest.mark.django_db def test_example(): from django.db import connection cur_ = connection.cursor() print cur_.db.settings_dict outputs: {'ENGINE':

pytest 3.fixture介绍一 conftest.py

心已入冬 提交于 2020-01-03 02:07:57
前言:   前面一篇pytest2 讲到用例加setup和teardown可以实现在测试用例之前或之后加入一些操作,但这种是整个脚本全局生效的,如果我想实现以下场景:   用例1需要先登录,用例2不需要登录,用例3需要先登录。很显然这就无法用setup和teardown来实现了。这就是本篇学习的目的,自定义测试用例的预置条件 fixture优势: 1.firture相对于setup和teardown来说应该有以下几点优势 命名方式灵活,不局限于setup和teardown这几个命名 conftest.py 配置里可以实现数据共享,不需要import就能自动找到一些配置 scope=”module” 可以实现多个.py跨文件共享前置 scope=”session” 以实现多个.py跨文件使用一个session来完成多个用例 fixture(scope="function", params=None, autouse=False, ids=None, name=None):   """使用装饰器标记fixture的功能""" 可以使用此装饰器(带或不带参数)来定义fixture功能。 fixture功能的名称可以在以后使用,引用它会在运行测试之前调用它: test模块或类可以使用pytest.mark.usefixtures(fixturename标记。

pytest文档6-fixture之yield实现teardown

一个人想着一个人 提交于 2020-01-03 02:07:37
前言 上一篇讲到fixture通过scope参数控制setup级别,既然有setup作为用例之前前的操作,用例执行完之后那肯定也有teardown操作。 这里用到fixture的teardown操作并不是独立的函数,用yield关键字呼唤teardown操作 scope="module" 1.fixture参数scope="module",module作用是整个.py文件都会生效,用例调用时,参数写上函数名称就行 # 新建一个文件test_f1.py # coding:utf-8 import pytest ''' ** 作者:上海-悠悠 QQ交流群:588402570** ''' @pytest.fixture(scope="module") def open(): print("打开浏览器,并且打开百度首页") def test_s1(open): print("用例1:搜索python-1") def test_s2(open): print("用例2:搜索python-2") def test_s3(open): print("用例3:搜索python-3") if __name__ == "__main__": pytest.main(["-s", "test_f1.py"]) 运行结果: ============================= test

pytest自动化3:fixture之conftest.py实现setup

 ̄綄美尐妖づ 提交于 2020-01-03 02:07:10
出处:https://www.cnblogs.com/yoyoketang/p/9390073.html 前言: 前面一篇讲到用例加setup和teardown可以实现在测试用例之前或之后加入一些操作,但这种是整个脚本全局生效的,如果我想实现以下场景: 用例1需要先登录,用例2不需要先登录,用例3需要先登录。很显然上篇学到的就不合适了,这就是本篇学习的目的,自定义测试用例的预置条件。 一、看个实例 通过以上实例,来了解到fixture特点: fixture(scope = "function", params=None, autouse=False, ids=None, name=None) 1. fixture使用装饰器标记功能 2. arg scope:scope有四个等级参数---- "function " (默认), " class", " module" or " session" arg params:一个可选的参数列表,它将导致多个参数调用fixture功能和所有测试使用它 arg autouse:如果为True,则为所有测试激活fixture func 可以看到它。 如果为False(默认值)则显式需要参考来激活fixture arg ids:每个字符串id的列表,每个字符串对应于params 这样他们就是测试ID的一部分。

How to use multiple pytest conftest files in one test run with a duplicated parser.addoption?

佐手、 提交于 2020-01-03 01:41:32
问题 I have a pytest testing project running selenium tests that has a structure like: ProjRoot | |_Pytest.ini |_____________TestFolderA | | | |_test_folderA_tests1.py | |_test_folderA_tests2.py | |____________TestFolderB | | | |_test_folderB_test1.py | |_test_folderA_tests2.py | | |___________TestHelperModules | | | |_VariousTestHelperModules | |____________DriversAndTools |___(contains chromedriver.exe, firefox profile folder etc) I have a confTest.py file which I currently run in the ProjRoot,