pytest

pytest parameters execution order for repeated test seems to be wrong

烈酒焚心 提交于 2019-12-12 05:59:08
问题 I am trying to run a test repeatedly which is a paramertrized. it doesn't seem to follow the order while executing test. I tried using pytest-repeat and pytest.mark.parametrize but i still didn't get the desired outcome. The code is conftest.py scenarios = [('first', {'attribute': 'value'}), ('second', {'attribute': 'value'})] id = [scenario[0] for scenario in scenarios] @pytest.fixture(scope="function", params=scenarios, ids=id) def **get_scenario**(request): return request.param test_param

How can I unittest whether PDF files have been generated correctly?

不羁岁月 提交于 2019-12-12 05:49:28
问题 I write a small python library that uses matplotlib and seaborn to draw charts, and I wonder how I can test whether the charts look like what I actually want. Thus, given a reference pdf file which I declared as correct, how would I automatically check whether it equals a dynamically generated file with dummy data? I assume that it's not reliable to hash the file due to timestamps etc. 回答1: Some ideas: Use diff-pdf Convert it to an image (e.g. using ImageMagick) and use PerceptualDiff Get the

Python3 - Pytest directory structure and imports

旧城冷巷雨未停 提交于 2019-12-12 05:29:27
问题 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.

py.test method to be executed only once per run

大城市里の小女人 提交于 2019-12-12 03:47:33
问题 Im new to pytest(and python). In have set of things to be executed only once before all my tests(ex:- starting android emulator, creating appium driver, instantiating all my page classes so that I can use them in tests). Btw, I have my tests in multiple classes. After bit of reading I thought @pytest.yield_fixture(scope="session", autouse=True) would do the trick.. but thats not what I see.. Please see below example.. import pytest class TestBase(): @pytest.yield_fixture(scope="session",

How do the arguments are being passed to test functions in tox/py.test?

女生的网名这么多〃 提交于 2019-12-12 02:07:50
问题 I'm learning to write tests with tox. How do the arguments are being passed to test functions in tox/py.test? For example in test_simple_backup_generation from tests/test_backup_cmd.py of django-backup extension there are three arguments tmpdir , settings , db . I don't have any idea where they came from. It's nothing said about this in tox documentation either. 回答1: These are pytest fixtures provided by pytest-django and pytest itself. 来源: https://stackoverflow.com/questions/39018056/how-do

TypeError: int() argument must be a string or a number, not 'Binary'

余生长醉 提交于 2019-12-12 01:14:39
问题 I'm working through http://blog.thedigitalcatonline.com/blog/2015/05/13/python-oop-tdd-example-part1/#.VxEEfjE2sdQ . I'm working through this iteratively. At this point I have the following Binary class: class Binary: def __init__(self,value): self.value = str(value) if self.value[:2] == '0b': print('a binary!') self.value= int(self.value, base=2) elif self.value[:2] == '0x': print('a hex!') self.value= int(self.value, base=5) else: print(self.value) return None I'm running through a suite of

Firefox crashes on close/quit - Pytest Selenium with RemoteWebDriver

[亡魂溺海] 提交于 2019-12-12 00:38:52
问题 I searched and found very similar mentions in older questions from several months ago which seemed to suggest problem should have been fixed by now, but it is still occurring for me. Pytest on my Linux server - Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700' Firefox on my remote Win7 laptop - browserVersion 50.0.2 Geckodriver on my remote Win7 laptop - geckodriver-v0.11.1-win64 . System info: host: 'XXXXXXXXX', ip: 'XXX.XXX.XXX.XXX', os.name: 'Windows 7',

pytest使用总结笔记

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 23:27:18
简介 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高。并且pytest兼容unittest的用例,支持的插件也更多 安装 pip install pytest 简单上手,创建个 test_sample.py文件 def func(x): return x + 1 def test_answer(): assert func(3) == 5 运行测试,直接在当前文件夹运行pytest collected 1 item test_sample.py F [100%] ================================= FAILURES ================================= _______________________________ test_answer ________________________________ def test_answer(): > assert func(3) == 5 E assert 4 == 5 E + where 4 = func(3) test_sample.py:6: AssertionError ============================ 1 failed in 0.12s ===

linux shell 多个命令一起执行的几种方法

牧云@^-^@ 提交于 2019-12-11 20:41:43
在命令行可以一次执行多个命令,有以下几种: 1.每个命令之间用;隔开 说明:各命令的执行结果,不会影响其它命令的执行。换句话说,各个命令都会执行, 但不保证每个命令都执行成功。 cd /home/PyTest/src; python suning.py 1 2.每个命令之间用&&隔开 说明:若前面的命令执行成功,才会去执行后面的命令。这样可以保证所有的命令执行完毕后,执行过程都是成功的。 cd /home/PyTest/src&&python suning.py 1 3.每个命令之间用||或者|隔开 说明:||是或的意思,只有前面的命令执行失败后才去执行下一条命令,直到执行成功 一条命令为止。 管道 可以将一个命令的输出导向另一个命令的输入,从而让两个(或者更多命令)像流水线一样连续工作,不断地处理文本流。在命令行中,我们用|表示管道 cd /home/PyTest/ 123 || echo "error234" cd /home/PyTest/ 123 | echo "error234" 在命令行可以一次执行多个命令,有以下几种: 来源: CSDN 作者: 迷麟Milin 链接: https://blog.csdn.net/qq_41705423/article/details/103498928

TDD test shows error even though response is correct

隐身守侯 提交于 2019-12-11 18:39:00
问题 I am following a tutorial about api here and I am following the exact code and I am also adapting the code for an Etsy app, here is my code for the second test, the tutorial code is identical to the tutorial, and works. The following code has been adapted to work with the Etsy APi. #etsywrapper/__core.py from . import session class Listings(object): def __init__(self, id): self.id = id def info(self): path = 'https://openapi.etsy.com/v2/listings/{}/inventory'.format(self.id) response =