gpt4 book ai didi

python - 为什么 `py.test --last-failed` 会跳过许多测试,尽管之前没有测试失败?

转载 作者:行者123 更新时间:2023-12-01 07:43:22 25 4
gpt4 key购买 nike

突然 py.test --last-failed 跳过了很多测试,尽管在之前的测试运行中没有测试失败。以下是首先运行 py.test --vv ,然后运行 ​​py.test --vv --last-failed 的输出:

$venv/bin/py.test -vv
======================================================================= test session starts =======================================================================
platform darwin -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0 -- /Users/lars/coding/talea/fahrtwind/products/backend/venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/lars/coding/talea/fahrtwind/products/backend, inifile: pytest.ini, testpaths: tests
plugins: forked-1.0.2, env-0.6.2, xdist-1.28.0, cov-2.7.1
collected 888 items
...
<HERE ALL 888 TESTS ARE RUN AND ALL PASS>
...
=================================================================== 888 passed in 63.89 seconds ===================================================================
$
$
$venv/bin/py.test -vv --last-failed
======================================================================= test session starts =======================================================================
platform darwin -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0 -- /Users/lars/coding/talea/fahrtwind/products/backend/venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/lars/coding/talea/fahrtwind/products/backend, inifile: pytest.ini, testpaths: tests
plugins: forked-1.0.2, env-0.6.2, xdist-1.28.0, cov-2.7.1
collected 303 items
run-last-failure: 181 known failures not in selected tests (skipped 206 files)
...
<HERE ONLY 303 TESTS ARE RUN>
...

为什么py.test --last-failed会跳过许多测试,尽管之前没有测试失败?

最佳答案

正如评论中所建议的,使缓存无效是解决方案:要么通过重新运行测试

$ pytest --cache-clear

或者,如果测试套件需要很长时间才能重新运行,只需删除项目根目录中的 .pytest_cache 目录(对于旧版本的pytest)。另外,引用 Clearing Cache content部分:

You can instruct pytest to clear all cache files and values by adding the --cache-clear option like this:

pytest --cache-clear

This is recommended for invocations from Continuous Integration servers where isolation and correctness is more important than speed.

因此,指示 CI 服务器在每次运行时使缓存失效是一个很好的做法,这样您在遇到由于本地缓存导致的意外故障时就有引用。

关于python - 为什么 `py.test --last-failed` 会跳过许多测试,尽管之前没有测试失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56577078/

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