gpt4 book ai didi

python - 在 pytest 中显示已通过测试的详尽信息

转载 作者:太空狗 更新时间:2023-10-30 02:53:40 25 4
gpt4 key购买 nike

当测试失败时,会有一个输出指示测试的上下文,例如

=================================== FAILURES ===================================
______________________________ Test.test_sum_even ______________________________

numbers = [2, 4, 6]

@staticmethod
def test_sum_even(numbers):
assert sum(numbers) % 2 == 0
> assert False
E assert False

test_preprocessing.py:52: AssertionError

如果我对通过的测试也想要同样的东西怎么办?以便我可以快速检查传递给测试的参数是否正确?

我尝试了命令行选项行 --full-trace-l--tb long-rpP ,但它们都不起作用。

有什么想法吗?

最佳答案

使用 --verbose 标志执行 pytest 将导致它在执行时列出每个测试的完全限定名称,例如:

tests/dsl/test_ancestor.py::TestAncestor::test_finds_ancestor_nodes
tests/dsl/test_and.py::TestAnd::test_aliased_as_ampersand
tests/dsl/test_and.py::TestAnd::test_finds_all_nodes_in_both_expressions
tests/dsl/test_anywhere.py::TestAnywhere::test_finds_all_nodes_when_no_arguments_given_regardless_of_the_context
tests/dsl/test_anywhere.py::TestAnywhere::test_finds_multiple_kinds_of_nodes_regardless_of_the_context
tests/dsl/test_anywhere.py::TestAnywhere::test_finds_nodes_regardless_of_the_context
tests/dsl/test_axis.py::TestAxis::test_finds_nodes_given_the_xpath_axis
tests/dsl/test_axis.py::TestAxis::test_finds_nodes_given_the_xpath_axis_without_a_specific_tag

关于python - 在 pytest 中显示已通过测试的详尽信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48678324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com