pytest

pytest running scenarios in the correct order in the class

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I have the following structure: class Test(object): def test_1(self): pass def test_2(self): pass def test_3(self): pass it runs great, NOW I'm adding the "scenarios" (as it's recommended at pytest - A quick port of “testscenarios” ): def pytest_generate_tests(metafunc): idlist = [] argvalues = [] for scenario in metafunc.cls.scenarios: idlist.append(scenario[0]) items = scenario[1].items() argnames = [x[0] for x in items] argvalues.append(([x[1] for x in items])) metafunc.parametrize(argnames, argvalues, ids=idlist) class Test(object):

Running pytest with cython - how to compile cython modules in pytest?

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a project organized as follows: where api.py imports cythonized extensions: """api.py"""" from _cython_foo import cython_fun My setup script builds the .pyx source inplace correctly and I'm able to use cython_fun in the installed package: import project.module1.api as module1 module1.cython_fun() # OK However, pytest complains that it cannot import the cython module since the compiled binaries are not in place until I invoke setup. project/module1/api.py:2: in <module> from _cython_foo import cython_fun E ImportError: No module named

pytest -- 中文文档

狂风中的少年 提交于 2019-12-03 02:28:53
pytest-chinese-doc pytest 官方文档(5.1.3版本) 的中文翻译,但不仅仅是简单的翻译: 更多的例子,尽量做到每一知识点都有例子; 更多的拓展阅读,部分章节添加了作者学习时,所查阅的资料; 所以这也是作者自身学习 pytest 的历程,希望能有更多的人了解这款优秀的测试框架; 已上传至GitHub,欢迎 star ; 环境 pytest 版本:5.1.3 python 版本:3.7.3 pipenv 版本:2018.11.26 使用 git clone git@github.com:luizyao/pytest-chinese-doc.git 仓库: docs/ 目录下包含所有的文章,以 markdown 格式编写; src/ 目录下包含所有的示例源码,以章节划分; 进入项目的根目录下,执行 pipenv install ,创建仓库的虚拟环境 目录 1、安装和入门 2、使用和调用 3、编写断言 4、fixtures:明确的、模块化的和可扩展的 5、猴子补丁 6、临时目录和文件 7、捕获标准输出和标准错误输出 8、捕获告警信息 来源: https://www.cnblogs.com/luizyao/p/11771740.html

8、pytest -- 捕获告警信息

两盒软妹~` 提交于 2019-12-03 02:27:12
目录 1. 告警信息的默认捕获行为 2. @pytest.mark.filterwarnings 3. 去使能告警信息的展示 4. 去使能告警的捕获行为 5. DeprecationWarning 和 PendingDeprecationWarning 告警 5.1. pytest.deprecated_call 方法 6. 编写触发期望告警的断言 6.1. 自定义失败时的提示消息 7. recwarn fixture 8. pytest 自定义的告警类型 pytest 3.1 版本新增特性 1. 告警信息的默认捕获行为 pytest 可以自动捕获测试中产生的告警信息,并在执行结束后进行展示; 下面这个例子,我们在测试中人为的产生一条告警: # src/chapter-8/test_show_warning.py import warnings def api_v1(): warnings.warn(UserWarning('请使用新版本的API。')) return 1 def test_one(): assert api_v1() == 1 我们也可以通过 -W arg 命令行选项来自定义告警的捕获行为: arg 参数的格式为: action:message:category:module:lineno ; action 只能在 "error", "ignore",

Pytest: how to skip the rest of tests in the class if one has failed?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm creating the test cases for web-tests using Jenkins, Python, Selenium2(webdriver) and Py.test frameworks. So far I'm organizing my tests in the following structure: each Class is the Test Case and each test_ method is a Test Step . This setup works GREAT when everything is working fine, however when one step crashes the rest of the "Test Steps" go crazy. I'm able to contain the failure inside the Class (Test Case) with the help of teardown_class() , however I'm looking into how to improve this. What I need is somehow skip(or xfail) the

PATH issue with pytest &#039;ImportError: No module named YadaYadaYada&#039;

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I used easy_install to install pytest on a mac and started writing tests for a project with a file structure likes so: repo/ repo/app.py repo/settings.py repo/models.py repo/tests/ repo/tests/test_app.py run py.test while in the repo directory, everything behaves as you would expect but when I try that same thing on either linux or windows (both have pytest 2.2.3 on them) it barks whenever it hits its first import of something from my application path. Say for instance from app import some_def_in_app Do I need to be editing my PATH to run py

How to use py.test from Python?

ぐ巨炮叔叔 提交于 2019-12-03 02:04:41
I'm working in a project that recently switched to the py.test unittest framework. I was used to call my tests from Eclipse, so that I can use the debugger (e.g. placing breakpoints to analyze how a test failure develops). Now this is no longer possible, since the only way to run the tests is via the command line blackbox. Is there some way to use py.test from within Python, so that one is not forced to drop out of the IDE? The tests should of course not be run in a separate process. I think I can now answer my own question, it's pretty simple: import py py.test.cmdline.main(args) Then I can

Python3 - Pytest directory structure and imports

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following project files (using Python3): pyproj ├―― __init__.py ├―― main.py ├―― module1.py ├―― module2.py └―― tests ├―― __init__.py └―― test_module.py module1 contains no imports. module2 imports from module 1 as follows: import module1 main.py imports from module1 and module2 as follows: from module1 import * from module2 import * I would like tests/test_module to be able to import from module2 and from module1, and to be able to run it using pytest from the pyproj directory. However attempting to import module2 using: from .

Can params passed to pytest fixture be passed in as a variable?

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have two simple test setups and I'm trying to group them in one fixture and want the test function to pass in the 'params' to the fixture. Here's a contrived example, to explain my question. Say I have the following pytest fixture: @pytest . fixture ( scope = "module" , params =[ 'param1' , 'param2' ]) def myFixture ( request ): if request . param == 'param1' : p = 5 elif request . param == 'param2' : p = 10 return p # would like to set request.param = ['param1'] for myFixture def test_madeup ( myFixture ): assert myFixture == 5

Can params passed to pytest fixture be passed in as a variable?

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have two simple test setups and I'm trying to group them in one fixture and want the test function to pass in the 'params' to the fixture. Here's a contrived example, to explain my question. Say I have the following pytest fixture: @pytest.fixture(scope="module", params=['param1','param2']) def myFixture(request): if request.param == 'param1': p = 5 elif request.param == 'param2': p = 10 return p # would like to set request.param = ['param1'] for myFixture def test_madeup(myFixture): assert myFixture == 5 # would like to set request.param