- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 pytest -tb=no
获得更多有用的输出短输出。我有存储在 JSON 文件中的集成测试,所以输出看起来都非常相似。
tests/test_dit_cli.py .......F............................. [ 29%]
...F...F.FF........F............................F...FFFFFFF [ 75%]
FFF.F..................F.....FF [100%]
===================== short test summary info =====================
FAILED tests/test_dit_cli.py::test_dits[dit_json7] - assert "Lin...
FAILED tests/test_dit_cli.py::test_dits[dit_json40] - assert "Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json44] - assert "Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json46] - assert "Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json47] - assert "Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json56] - assert "Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json85] - assert "Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json89] - AssertionE...
FAILED tests/test_dit_cli.py::test_dits[dit_json90] - AssertionE...
FAILED tests/test_dit_cli.py::test_dits[dit_json91] - AssertionE...
FAILED tests/test_dit_cli.py::test_dits[dit_json92] - AssertionE...
FAILED tests/test_dit_cli.py::test_dits[dit_json93] - AssertionE...
FAILED tests/test_dit_cli.py::test_dits[dit_json94] - AssertionE...
FAILED tests/test_dit_cli.py::test_dits[dit_json95] - AssertionE...
FAILED tests/test_dit_cli.py::test_dits[dit_json96] - assert 'Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json97] - assert 'Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json98] - assert "Li...
FAILED tests/test_dit_cli.py::test_dits[dit_json100] - Assertion...
FAILED tests/test_dit_cli.py::test_dits[dit_json119] - assert "L...
FAILED tests/test_dit_cli.py::test_dits[dit_json125] - Assertion...
FAILED tests/test_dit_cli.py::test_dits[dit_json126] - Assertion...
================= 21 failed, 106 passed in 2.94s ==================
看到同样的
tests/test_dit_cli.py::test_dits[dit_json126]
20 次并不能帮助我了解项目中出了什么问题,所以我通常一次只修复一个测试错误。每个测试条目都有关于正在运行的测试类型和预期结果的额外信息,但我不知道如何将这些信息输入 pytest。我希望有这样的事情:
===================== short test summary info =====================
FAILED [func, vanilla Python] - assert "Li...
FAILED [Thing, value assignment] - assert "Li...
FAILED [TypeMismatch, String var assigned to List] - assert "Lin...
通过提供
ids
的值,我实际上接近了这一点。在
parametrize
称呼。
def pytest_generate_tests(metafunc: Metafunc):
for fixture in metafunc.fixturenames:
if fixture == "dit_json":
test_dicts = list(load_from_json())
titles = [test_dict["title"] for test_dict in test_dicts]
metafunc.parametrize(argnames=fixture, argvalues=test_dicts, ids=titles)
FAILED tests/test_dit_cli.py::test_dits[TypeMismatch, List var assigned to String]
FAILED tests/test_dit_cli.py::test_dits[import, anon import referenced in list assignment]
所以,我真的很接近,我只想删除文件路径,以便行更短。有没有办法改变它认为测试所在的文件路径?或者一个可以让我任意修改摘要输出的钩子(Hook)?我尝试修改
pytest_collection_modifyitems
和改变
item.fspath
,但它没有改变输出中的任何内容。我已经看到了修改有关输出的许多其他内容的方法,但没有专门针对该文件路径。
最佳答案
如果您只想缩短简短摘要信息中的 nodeids,您可以覆盖 nodeid
对象的 report
属性。一个简单的例子:
def pytest_runtest_logreport(report):
report.nodeid = "..." + report.nodeid[-10:]
放置在您的
conftest.py
中,会将每个 nodeid 截断为其最后十个字符:
=========================== short test summary info ===========================
FAILED ...st_spam[0] - assert False
FAILED ...st_spam[1] - assert False
FAILED ...st_spam[2] - assert False
FAILED ...st_spam[3] - assert False
FAILED ...st_spam[4] - assert False
FAILED ...:test_eggs - assert False
如果您想要一个完全自定义的简短测试摘要行,您需要实现自定义
TerminalReporter
并在测试运行中尽早替换原始代码。示例 stub :
import pytest
from _pytest.terminal import TerminalReporter
class MyReporter(TerminalReporter):
def short_test_summary(self):
# your own impl goes here, for example:
self.write_sep("=", "my own short summary info")
failed = self.stats.get("failed", [])
for rep in failed:
self.write_line(f"failed test {rep.nodeid}")
@pytest.mark.trylast
def pytest_configure(config):
vanilla_reporter = config.pluginmanager.getplugin("terminalreporter")
my_reporter = MyReporter(config)
config.pluginmanager.unregister(vanilla_reporter)
config.pluginmanager.register(my_reporter, "terminalreporter")
这将产生一个摘要部分,如
========================== short test summary info ===========================
failed test tests/test_spam.py::test_spam[0]
failed test tests/test_spam.py::test_spam[1]
failed test tests/test_spam.py::test_spam[2]
failed test tests/test_spam.py::test_spam[3]
failed test tests/test_spam.py::test_spam[4]
failed test tests/test_spam.py::test_eggs
注意,上面的
MyReporter.short_test_summary()
impl 并不完整,仅用于演示目的!如需引用,请查看
pytest
impl 。
关于python - Pytest:自定义简短的测试摘要信息,删除文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65526149/
void main(){ char c; unsigned char uc; unsigned short us1, us2; short s1, s2; c
我要删除 wordpress html 格式在 woocommerce 产品简短描述中。添加 电话 到处标记。我知道如何在 wp 帖子和页面中做到这一点 remove_filter( 'the_exc
我通常会打开一个命令的联机帮助页,该命令已经知道我正在搜索的选项并阅读其描述。有时只需搜索该选项即可立即生效,有时该选项在其他地方被引用,有时该选项仅作为子字符串出现在前面的文本中。 作为一个具体的例
假设我们有一个编号的圆圈。我们想从 A 点到 B 点,但不知道应该向左还是向右。你会如何使用数字来计算你应该朝哪个方向前进? 示例: 我们目前在 1。我们想继续 5。我可以直观地看到 5 更近,所以我
我正在使用以下内容将产品名称和价格添加到悬停框。 在 functions.php 中 // Alter produt loop individual products add_action( 'woo
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我有一个for循环 for ($x=1; $x<=5; $x++){ ($x == 3)? continue : true; //some code here } 现在执行时出现错误
我刚刚开始我的第一个 Java Swing 项目(之前主要做基于 Web 的应用程序),并尝试了解如何构建一个适当的架构,并在 MVC 组件之间分离关注点。 我发现的几乎所有文档都非常深入地介绍了每个
我是一名优秀的程序员,十分优秀!