pytest

Py.Test : Reporting and HTML output

℡╲_俬逩灬. 提交于 2019-12-06 18:27:29
问题 This is not a technical question at all really. However, I can not locate my .HTML report that is supposed to be generated using: py.test --cov-report html pytest/01_smoke.py I thought for sure it would place it in the parent location, or the test script location. Does neither and I have not been able to locate. So I am thinking it is not being generated at all? 回答1: I think you also need to specify the directory/file you want coverage for like py.test --cov=MYPKG --cov-report=html after

on MAC OS X, py.test not recognized as a command

ⅰ亾dé卋堺 提交于 2019-12-06 15:43:38
On MAC OS X 10.10; I installed pytest 2.6.4; however in Terminal If I write py.test or even py.test --version; I get the error: -bash: py.test command not found (a) Am I missing anything? What do I do to make the pytest tool recognizable. I searched alot; but couldn't find any info except http://teckla.idyll.org/~t/transfer/py.test.html I checked in the PyCharm preferences, I don't see py.test interpreter listed there. However, pip freeze displays pytest 2.6.4 installed. (b) Is PYTHONPATH required to be set on MAC? Although I've seen setting it is not required on Windows. Appreciate any

Pytest: how to display generated report after test run?

自闭症网瘾萝莉.ら 提交于 2019-12-06 15:26:22
I am using pytest in combination with the pytest-html plugin which generates an HTML report after the test has run. I am using an auto-wired session fixture to automatically open the generated HTML report in a browser: @pytest.fixture(scope="session", autouse=True) def session_wrapper(request): print('Session wrapper init...') yield # open report in browser on Mac or Windows, skip headless boxes if platform.system() in ['Darwin', 'Windows']: html_report_path = os.path.join(request.config.invocation_dir.strpath, request.config.option.htmlpath) open_url_in_browser("file://%s" %html_report_path)

py.test teardown see if the test failed and print subprocess output

你。 提交于 2019-12-06 13:35:36
I want to print subprocess output in py.test teardown if the test is failed - or send it to any other human readable output. Is it possible to check if the test has failed in teardown? Any other ways to get the output of subprocess commands only during test failures? My code: """Test different scaffold operations.""" import subprocess import pytest from tempfile import mkdtemp @pytest.fixture(scope='module') def app_scaffold(request) -> str: """py.test fixture to create app scaffold.""" folder = mkdtemp(prefix="websauna_test_") cmdline = ["..."] worker = subprocess.Popen(cmdline, stdout

pytest--命令行参数

懵懂的女人 提交于 2019-12-06 12:54:04
使用pytest --help可以查看全部选项 ​ -v:pytest -v 说明:可以输出用例更加详细的执行信息,比如用例所在的文件及用例名称等 -q(--quiet) 该选项的作用与-v/--verbose的相反,简化输出信息。 -k -k 选项允许使用表达式指定希望执行的测试用例,例如:test_answer() test_result() 那么可以用表达式"answer or result"来筛选。结合-v或者--verbose查看是否符合预期,如下图: -m   标记(marker)用于标记测试并分组,以便快速选中并运行。以test_answer() 、 test_result1()为例,它们甚至都不在同一个文件里,如果希望同时运行它们,那么可以预先做好标记。   这里使用什么标记名可以自定义,比如使用run_cases则可以用 @pytest.mark.run_cases这样的装饰器(decorator)来标记,如下所示: 给test_result()也做上同样的标记。有相同标记的测试用例,可以一起运行。使用 pytest -m run_cases 命令就可以同时运行test_answer()和test_result1()。如下图:  使用-m选项还可以用表达式指定多个标记各。使用-m "mark1 and mark2"可以同时选中带有这两个标记的所有测试用例。使用-m

pytest 运行SyntaxError: invalid syntax

a 夏天 提交于 2019-12-06 10:05:21
问题描述:运行pytest 报语法错误 原因:猜想装了两套python,,而导入 pytest 无效,可能一些环境变量未配置导致得,不是很清楚,但是我切换成了 另一套python 环境 ,在pycharm里 install pytest 模块就好了 解决方案: 如果哪位大佬知道 ,请留言,谢谢了 来源: https://www.cnblogs.com/godfather520/p/11975932.html

Why does the simplest requests_mock example fail with pytest?

隐身守侯 提交于 2019-12-06 09:01:19
问题 I have a peculiar problem with requests_mock . I want to use it with pytest to test my API wrapper library. I've tried to use the first example in the requests_mock docs, except I put it in a test_mock() -function and added an assert -statement for pytest to discover it. The following code fails: # tests/test_mock.py import requests import requests_mock with requests_mock.Mocker() as m: def test_mock(): m.get('http://test.com', text='resp') assert requests.get('http://test.com').text == 'resp

Change pytest testsuite name in xml report

ぃ、小莉子 提交于 2019-12-06 08:52:49
问题 Because we started same tests with different interface, then take all reports and send them to jenkins. It's difficult to recognise with what interface we have errors. Before we use nose, it has parameter "--xunit-testsuite-name", has pytest analog? I want to change name of test suite in reports testsuite errors="0" failures="0" name=" pytest " skips="0" tests="12" time="103.702" to testsuite errors="0" failures="0" name=" inteface1 " skips="0" tests="12" time="103.702" 回答1: You can add a

pytest - use funcargs inside setup_module

二次信任 提交于 2019-12-06 08:35:27
问题 I include at conftetst.py my own command line options def pytest_addoption(parser): parser.addoption("--backend" , default="test_backend", help="run testx for the given backend, default: test_backend") and def pytest_generate_tests(metafunc): if 'backend' in metafunc.funcargnames: if metafunc.config.option.backend: backend = metafunc.config.option.backend backend = backend.split(',') backend = map(lambda x: string.lower(x), backend) metafunc.parametrize("backend", backend) If I use this

python测试框架

本小妞迷上赌 提交于 2019-12-06 08:30:24
一、测试常用规则 一个测试单元必须关注一个很小的功能函数,证明它是正确的; 每个测试单元必须是完全独立的,必须能单独运行。这样意味着每一个测试方法必须重新加载数据,执行完毕后做一些清理工作。通常通过setUp()和setDown()方法处理; 编写执行快速的测试代码。在某些情况下,测试需要加载复杂的数据结构,而且每次执行的时候都要重新加载,这个时候测试执行会很慢。因此,在这种情况下,可以将这种测试放置一个后台的任务中。 在编写代码前执行完整的测试,而且在编写代码后再重新执行一次。这样能保证你后来编写的代码不会破坏任何事情; 在提交代码前执行完整的测试; 如果在开发期间被打断了工作,写一个打断的单元测试,关于你下一步将要开发的。当你回来工作时,你能知道上一步开发到的指针; 单元测试函数使用长的而且具有描述性的名字。在正式执行代码中,可能使用square()或sqr()取名,但是在测试函数中,你必须取像test_square_of_number_2()、test_square_negativer_number()这些名字,这些名字描述更加清楚; 测试代码必须具有可读性; 单元测试对新进的开发人员来说是工作指南。 二、python常用的测试框架 1. unittest unittest是Python内置的标准类库 unittest 和 JUnit类似