python - 有没有办法只标记一个要运行的测试?
问题描述
我正在调试一个失败的测试。有没有办法只标记一个要运行的测试?
就像是:
@pytest.only # it doesn't work
def test_some_test():
...
解决方案
您可以用 标记您的测试pytest.mark
。标记是动态创建的,因此您几乎可以选择任何名称。这是文档的链接。
例如在tt.py
:
import pytest
@pytest.mark.one_test
def test_foo():
assert 1 == 1
def test_bar():
assert 2 == 2
enter code here
然后运行pytest tt.py -m one_test
:
pytest tt.py -m one_test
======================= test session starts =========================
platform darwin -- Python 3.6.3, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
rootdir: /Users/foobarna/workspace/random, inifile:
collected 2 items / 1 deselected
tt.py .
[100%]
============= 1 passed, 1 deselected in 0.04 seconds ================
推荐阅读
- javascript - 将 mailgun 合并到控制器中
- c# - Try and Catch 块不扔任何东西
- php - PHP 回声样式
- java - 如何在底部工作表对话框片段中设置文本按钮?
- python - pycharm 刽子手游戏中的问题。这里是初学者(显然)。TypeError: 'builtin_function_or_method' 类型的对象没有 len()
- c++ - 创建 GL_TEXTURE_2D_ARRAY 后访问冲突
- python - 为什么加密中的AES加密会产生汉字
- django - Django OnetoOne 字段未填充
- java - 哪种数据结构更适合使用顺序搜索来搜索元素 - 数组列表或链接列表?
- python - 通过代码调用函数和参数