你如何测试pytest中的单个文件?我只能在文档中找到忽略选项而不"仅测试此文件"选项.
最好这可以在命令行上工作而不是setup.cfg,因为我想在ide中运行不同的文件测试.整个套房需要很长时间.
Bry*_*ant 50
只需pytest使用文件路径运行即可
就像是
pytest tests/unit/some_test_file.py
lmi*_*asf 43
这很简单:
$ pytest -v /path/to/test_file.py
Run Code Online (Sandbox Code Playgroud)
该-v标志是增加冗长.如果要在该文件中运行特定测试:
$ pytest -v /path/to/test_file.py::test_name
Run Code Online (Sandbox Code Playgroud)
如果你想运行测试,你可以使用以下模式:
$ pytest -v -k "pattern_one or pattern_two" /path/to/test_file.py
Run Code Online (Sandbox Code Playgroud)
您还可以选择标记测试,因此您可以使用该-m标志运行标记测试的子集.
test_file.py
def test_number_one():
"""Docstring"""
assert 1 == 1
@pytest.mark.run_these_please
def test_number_two():
"""Docstring"""
assert [1] == [1]
Run Code Online (Sandbox Code Playgroud)
运行测试标记为run_these_please:
$ pytest -v -m run_these_please /path/to/test_file.py
Run Code Online (Sandbox Code Playgroud)
Jon*_*297 14
这对我有用:
python -m pytest -k some_test_file.py
Run Code Online (Sandbox Code Playgroud)
这也适用于单个测试功能:
python -m pytest -k test_about_something
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24644 次 |
| 最近记录: |