pytest

pytest问题笔记一:mark 警告 PytestUnknownMarkWarning: Unknown pytest.mark.

℡╲_俬逩灬. 提交于 2020-03-08 10:36:08
运行用例的时候,老是弹出警告 PytestUnknownMarkWarning: Unknown pytest.mark.run_these_pl ease - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html warnings.warn( -- Docs: https://docs.pytest.org/en/latest/warnings.html ================================================================== 1 warning in 0.28s ================================================================== 尝试了其他博主的三种方式( https://www.cnblogs.com/zzllovehappy/p/11270933.html ),只有以下方法生效了,以此记录 新增一个配置ini文件,并在文件中输入: [pytest] markers = run_these_please #标记名称 来源: CSDN 作者:

运行pytest,报错\"AttributeError: 'module' object has no attribute 'xxx'\"

巧了我就是萌 提交于 2020-03-08 07:55:31
最近学习pytest被此问题困扰,敲脑壳,实在是不该。百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢。 报错信息如下: 网上解决方法是这样的: 1. 命名py脚本时,不要与python预留字,模块名等相同 2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可 PS:此方法在我的问题上解决不了。 自己的解决方法: 卸载 and 重装 pytest库 1、打开cmd,输入命令:pip uninstall pytest 2、若提示删除失败,找到D:\python\Lib\site-packages的【pytest】文件(这里的路径根据个人安装路径不同而不同),将该文件直接删除,然后再次重复第一步即可。 3、为了查看是否卸载完成,输入pip list 查看安装的所有模块,如果卸载模块操作成功,则不会再看到【pytest】模块 4、再使用 pip install pytest 命令重新安装 运行pytest后,展示了版本号,则安装成功 来源: https://www.cnblogs.com/happywu205/p/11567882.html

Why I'm getting F811 error in this code?

心不动则不痛 提交于 2020-03-06 09:27:31
问题 I have my tests divided in multiple files with share a helpers.py with common functions to all tests. For example: helpers.py @pytest.fixture def settings(): test_component_a.py from helpers import settings @pytest.fixture def fixture_A(settings): @pytest.fixture def fixture_B(settings): def test_A(fixture_A): def test_B(fixture_B): I would like to know why in any definition of def fixture_X(settings) I'm getting the "error" F811 - redefinition of unused 'settings' from line 1 . The code is

Why I'm getting F811 error in this code?

落爺英雄遲暮 提交于 2020-03-06 09:25:14
问题 I have my tests divided in multiple files with share a helpers.py with common functions to all tests. For example: helpers.py @pytest.fixture def settings(): test_component_a.py from helpers import settings @pytest.fixture def fixture_A(settings): @pytest.fixture def fixture_B(settings): def test_A(fixture_A): def test_B(fixture_B): I would like to know why in any definition of def fixture_X(settings) I'm getting the "error" F811 - redefinition of unused 'settings' from line 1 . The code is

关于《Selenium3自动化测试实战--基于python语言》

我是研究僧i 提交于 2020-03-05 17:27:28
2016年1月,机缘巧合下我出版了《Selenium2自动化测试实战--基于python语言》这本书,当时写书的原因是,大部分讲Selenium的书并不讲编程语言和单元测试框,如果想在项目中使用Selenium,几乎离不开编程语言和单元测试框架,难道你只用Selenium IDE去录制/回放脚本么? 没想到受到许多测试人员的欢迎,我会时常去看网上的书评。大多是感谢的留言,书的销量也印证了这一点,当然,也有批评和建议。在此,表示感谢。 随着,我对Selenium自动化技术的理解,越来越发现《Selenium2自动化测试实战--基于python语言》书中有许多不足之处。 2017年的时候,我就有萌生了要重写一版的想法,当时能想到的改动的地方不多。只是一定未开始动笔。知道2018年下半年,我才开始重新写这本书。 接下来,我将简单的向你介绍以下新书的章节,以及我的改动。 第一章: 不讲什么是软件测试,以及测试的分类这些过于基础的东西了。快速的帮助你对自动化测试,以及Selenium、appium有一个认识。 第二章: 搭建环境。 第三章: python基础,修改了部分列子,以及我认识上的错误,比如,我把 list/列表 称为 数组 ,这其实源于我学C/Java语言,就把他们的叫法照搬了过来。显然,是不太合适的。随着对python的语言的使用,也有了更多的认识。如果你还不会python

Subprocesses not running with pytest Error Processing Test

旧城冷巷雨未停 提交于 2020-03-05 05:03:09
问题 I am currently converting my unittest setup over to pytest, everything is working however on certain tests I run a command line process in order to load code into the hardware I have attached via USB. this process works fine with unittest however when using pytest or nose2 I get the response ------------------------------------------------ Captured stderr call ------------------------------------------------- Error processing Test this happens just when my process begins to run? I get no

Subprocesses not running with pytest Error Processing Test

巧了我就是萌 提交于 2020-03-05 05:01:06
问题 I am currently converting my unittest setup over to pytest, everything is working however on certain tests I run a command line process in order to load code into the hardware I have attached via USB. this process works fine with unittest however when using pytest or nose2 I get the response ------------------------------------------------ Captured stderr call ------------------------------------------------- Error processing Test this happens just when my process begins to run? I get no

How to clear captured stdout/stderr in between of multiple assert statements

旧巷老猫 提交于 2020-03-04 06:07:56
问题 I have some tests with assertions in loop, each assertion is kinda like separate test and I don't want previous assertions' output to pollute error logs of current failed assertion. def test_foos(captured): foos = [] # some data for foo, bar in foos: captured.clear() assert logic(foo) == bar I have found caplog.clear but it doesn't seem to work. 回答1: Parametrize your test. Pass the foos as parameter and pytest will run the test assert line multiple times, recording success/failure as if each

Meaning of yield within fixture in pytest

回眸只為那壹抹淺笑 提交于 2020-03-03 13:59:48
问题 I read the documentation at docs.pytest.org I'm not sure about the meaning of the statement: yield smtp_connection Can please someone explain what yield does, and if it's mandatory? 回答1: First of all it's not mandatory!!! Yield execute test body, for example, you can set up your test with pre-condition and post condition. For this thing we can use conftest.py: import pytest @pytest.fixture def set_up_pre_and_post_conditions(): print("Pre condition") yield # this will be executed our test

Run trace.py with pytest

为君一笑 提交于 2020-03-03 03:03:08
问题 I'm trying to get coverage using trace.py when running pytest . I know that pytest has its own coverage plugin pytest-cov but restrictions (number of times each line is executed is unavailable) do not allow me to use that right now. The same for coverage.py I'm trying this command: python3.4 -m trace -c -m -C . pytest test_script.py test_script.py : class TestScript(): def test_print(self): print ('Hello') The output is: nikhilh$ python3.4 -m trace -c -m -C . pytest test_script.py pytest: