python - 使用 py.test 但在命令行上排除测试列表?

标签 python pytest python-unittest

我想用 py.test 排除一个测试列表(大约 5 个项目)。

我想通过命令行将此列表提供给 py.test。

我想避免修改源代码。

怎么做?

最佳答案

你可以使用 tests selecting expression , 选项是 -k。如果您有以下测试:

def test_spam():
    pass

def test_ham():
    pass

def test_eggs():
    pass

调用 pytest:

pytest -v -k 'not spam and not ham' tests.py

你会得到:

collected 3 items

pytest_skip_tests.py::test_eggs PASSED             [100%]

=================== 2 tests deselected ===================
========= 1 passed, 2 deselected in 0.01 seconds =========

关于python - 使用 py.test 但在命令行上排除测试列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47691512/

相关文章:

python - 如何在python中使用fileinput保存文件?给出属性错误: 'FileInput' object has no attribute 'read'

python - 基于 `pytest` 和 `yield` 的测试

python - 由于 __init__ 构造函数而产生的 Pytest 集合警告

python - 为什么在 self.assertEqual 签名中调用字典键时出现 KeyError ?

python - 了解在单元测试类中捕获 ValueError 的语句

Python单元测试,测试用例之前的声明

python - FK select 的显示选项 - Django Rest Framework

python - matplotlib 图像以黑白显示,但我想要灰色

python - 无法使用 python3 反序列化关键数据

python - pytest:是否可以从代码中启用标记?