我是Pytest和开发新手..我试图运行一个简单的pytest断言,但是我得到了错误:
KeyError: WindowsPath('D:/ireact-tester-if/Lib/site-packages/matplotlib/testing/conftest.py')
During handling of the above exception, another exception occurred:
lib\site-packages\py\_path\common.py:383: in visit
for x in Visitor(fil, rec, ign
我的pyproject.toml中有以下内容
[tool.pytest.ini_options]
markers = [
"plot: marks SLOW plot tests (deselect with '-m \"not plot\"')",
"open_tutorial: marks the open_tutorial (which opens VSCode all the times)"
]
我有一堆相应的测试方法。
如果我跑了
coverage run --branch -m pytest -m &
对于我的代码,pytest_status‘’finished‘变量正在以非常有趣的方式递增。有时,我可以看到'2‘或'3’(我希望每个run_test函数调用都有相应的增量):
test 1/53: success
test 1/53: success
test 1/53: success
test 1/53: success
test 1/53: success
test 1/53: success
test 1/53: success
test 1/53: success
test 1/53: success
test 1/53: success
test 1/53: su
我正在测试模块match_view.py中的一个函数(如下所示)
from dbaccess.repository import bulk_update_zingr_id, bulk_insert_ingredients_matching_table
from services.matching_ingr_zingr import ingr_zing_match_mult_search
from services.FileStorage import dumpModel
from flask import Blueprint, request
from datetime import date
在编写单元测试时,我通常使用pytest.mark.parametrize装饰器。我突然意识到,当测试引发异常的函数时,我可以执行如下操作:
bar.py
def foo(n: int, threshold: int = 1) -> int:
if n >= threshold:
return n
else:
raise ValueError(f'n: {n} < {threshold} (threshold)')
test_bar.py
import pytest
from bar import foo
te
我已经看过最热的文档了。第7.4.3节给出了注册标记的说明。我严格按照指示办事,但似乎对我没有用。
我正在使用Python2.7.2和pytest 2.5.1。
我的项目根部有一个pytest.ini文件。以下是该文件的全部内容:
[pytest]
python_files=*.py
python_classes=Check
python_functions=test
rsyncdirs = . logs
rsyncignore = docs archive third_party .git procs
markers =
mammoth: mark a test as part of
我使用Pytest在两个列表上运行测试
import pytest
def test_TestsRunAfterFailure():
x = [1,2,3,4]
test = [4, 5, 6]
for t in test:
assert (t in x)
我希望测试能够测量每个变量,即使在第一次失败之后也是如此,所以我知道哪些变量失败了。生成的输出表明它在第一次故障后停止。
E assert 5 in [1, 2, 3, 4]
我在googled上搜索了这个问题,建议用下面的论点运行pytest