2024-10-06 10:34:22 发布
网友
如何在pytest中测试单个文件?我只能在文档中找到ignore选项和no“testthisfileonly”选项。
最好在命令行而不是setup.cfg上运行,因为我希望在ide中运行不同的文件测试。整个套间太长了。
setup.cfg
这很简单:
$ pytest -v /path/to/test_file.py
-v标志用于增加详细程度。如果要在该文件中运行特定测试:
-v
$ pytest -v /path/to/test_file.py::test_name
如果要运行测试,可以使用以下模式的名称:
$ pytest -v -k "pattern_one or pattern_two" /path/to/test_file.py
您还可以选择标记测试,因此可以使用-m标志来运行标记测试的子集。
-m
测试文件.py
def test_number_one(): """Docstring""" assert 1 == 1 @pytest.mark.run_these_please def test_number_two(): """Docstring""" assert [1] == [1]
要运行标记为run_these_please的测试:
run_these_please
$ pytest -v -m run_these_please /path/to/test_file.py
只需使用文件的路径运行pytest
pytest
有点像
pytest tests/unit/some_test_file.py
这对我有效:
python -m pytest -k some_test_file.py
这也适用于单独的测试功能:
python -m pytest -k test_about_something
这很简单:
-v
标志用于增加详细程度。如果要在该文件中运行特定测试:如果要运行测试,可以使用以下模式的名称:
您还可以选择标记测试,因此可以使用
-m
标志来运行标记测试的子集。测试文件.py
要运行标记为
run_these_please
的测试:只需使用文件的路径运行
pytest
有点像
pytest tests/unit/some_test_file.py
这对我有效:
这也适用于单独的测试功能:
相关问题 更多 >
编程相关推荐