Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么'py.test--last failed'跳过许多测试,尽管以前没有测试失败过?_Python_Pytest - Fatal编程技术网

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

Python 为什么'py.test--last failed'跳过许多测试,尽管以前没有测试失败过?,python,pytest,Python,Pytest,突然退出py.test——上一次失败的跳过了很多测试,尽管在上一次测试运行中没有测试失败。这是第一次运行的py.test--vv,然后是py.test--vv--last failed的输出: $venv/bin/py.test -vv ======================================================================= test session starts =======================================

突然退出
py.test——上一次失败的
跳过了很多测试,尽管在上一次测试运行中没有测试失败。这是第一次运行的
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>
...
$venv/bin/py.test-vv
===============================================================================================================测试会话开始=======================================================================
平台darwin——Python 3.7.3、pytest-4.6.3、py-1.8.0、Plugy-0.12.0——/Users/lars/coding/talea/fahrtwind/products/backend/venv/bin/python3
cachedir:.pytest\u缓存
rootdir:/Users/lars/coding/talea/fahrtwind/products/backend,ini文件:pytest.ini,testpath:tests
插件:forked-1.0.2、env-0.6.2、xdist-1.28.0、cov-2.7.1
收集了888件物品
...                                                                                                                                     
...
=============================================================================================================888在63.89秒内通过===================================================================
$
$
$venv/bin/py.test-vv--上次失败
===============================================================================================================测试会话开始=======================================================================
平台darwin——Python 3.7.3、pytest-4.6.3、py-1.8.0、Plugy-0.12.0——/Users/lars/coding/talea/fahrtwind/products/backend/venv/bin/python3
cachedir:.pytest\u缓存
rootdir:/Users/lars/coding/talea/fahrtwind/products/backend,ini文件:pytest.ini,testpath:tests
插件:forked-1.0.2、env-0.6.2、xdist-1.28.0、cov-2.7.1
共收集303项
运行上次失败:181个已知失败不在所选测试中(跳过206个文件)
...
...

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

正如注释中所建议的,使缓存无效是解决方案:或者通过

$ pytest --cache-clear
或者,如果测试套件需要花费大量时间重新运行,只需删除项目根目录中的
.pytest\u cache
目录(对于
pytest
的较旧版本,则删除
.cache
)。此外,引用该节:

您可以通过如下方式添加
--cache clear
选项,指示
pytest
清除所有缓存文件和值:

pytest --cache-clear
对于从持续集成服务器进行的调用,建议这样做,因为隔离和正确性比速度更重要


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

可能是一次运行中最后一次失败,但实际上失败了?呃,如果以前没有测试失败,那么它不应该跳过所有测试吗?为什么您会对它跳过“许多”测试感到惊讶?
-vv
意味着什么?
-v
?py.test--last failed
的行为是,如果non之前失败,则重新运行所有测试。很奇怪,它只是运行了一些以前没有失败的测试!如果上一次运行成功,
pytest
应响应
no previous failed tests,而不是在重新运行上次失败时取消选择项。缓存中的某些内容过时(可能被某个插件污染或处理不正确?)-能否使用
pytest--cache clear
重新运行测试,然后使用
pytest--last failed--collect only
测试集合?