为什么 Cargo nextest 在找到我的一些测试后选择不运行它们?

问题描述 投票:0回答:1

我刚刚运行了一组我一直在开发的测试。

突然我开始得到这样的总结:

Summary [   0.598s] 26/28 tests run: 24 passed, 2 failed, 0 skipped

更具体地说,我注释掉了足够的测试来运行“直接数量”的测试。这是报告:

Summary [   0.588s] 27 tests run: 26 passed, 1 failed, 0 skipped

然后我将此测试添加到

mod tests

#[test]
fn do_test() -> Result<()> {
    assert!(false);
    Ok(())
}

我现在得到的报告是:

Summary [   0.607s] 26/28 tests run: 24 passed, 2 failed, 0 skipped

“2失败”:似乎是明智的。但更困难的是:它告诉我实际通过的测试少了 2 个。 同样令人困惑的是,突然“不确定”已经运行了多少测试。

根据 cafce25 的评论进行更新
事实上,“26/28 测试”的意思是“有 28 个测试,但只运行了 26 个”。那么问题是:为什么这两个未运行的测试没有运行?

一个重要的事实可能是我在这里使用 crate mockall,包括指令

#[double]

任何人都可以解释发生了什么以及在下一个文档中可以解释这一点吗?

更多详情

所以这是一次运行,显示在运行开始时宣布了 29 个测试...但最后的摘要报告显示有 4 个测试未运行:

(doc_indexer) D:\...\populate_index_module>cargo nextest run -v
   Compiling populate_index_module v0.1.0 (D:\...\populate_index_module)
    Finished test [unoptimized + debuginfo] target(s) in 4.33s
    Starting 29 tests across 4 binaries
        PASS [   0.031s] populate_index_module auxiliaries::tests::working_up_from_app_execution_cwd_finds_doc_indexer_project_root_dir
        PASS [   0.025s] populate_index_module handling_framework::tests::unreadable_zip_complaint_causes_continue_not_error_propagation::case_1
        ...
        PASS [   0.088s] populate_index_module::test_1 ldocs_contain_more_than_one_para
        FAIL [   0.232s] populate_index_module text_document::tests::deliberately_failing_test

...测试运行报告结束:

        PASS [   0.557s] populate_index_module::test_1 all_text_in_files_is_correctly_caught::case_2
------------
     Summary [   0.599s] 25/29 tests run: 22 passed, 3 failed, 0 skipped
        FAIL [   0.232s] populate_index_module text_document::tests::deliberately_failing_test
        FAIL [   0.266s] populate_index_module::test_1 framework_init_populates_the_index_by_submitting_bulk_inserts
        FAIL [   0.208s] populate_index_module::test_1 test_thing
error: test run failed

注意,开头的“起始”列表实际上只列出了上面的 17 个结果。有更多“总”测试,因为我正在使用 crate rstest 来参数化测试。

奇怪的东西

cargo nextest
有相当多的选项和标志(尝试
cargo nextest run --help
)...我发现一个叫做
--run-ignored
。所以运行这个:

(doc_indexer) D:\...\populate_index_module>cargo nextest run --run-ignored all

结果非常奇怪:有时它会运行所有 29 个测试。有时26/29。有时 23/29。有时 27/29。 ...此时我将转到 Github 位置,以便 nextest 提出问题。但如果有人能提供任何解释,我想听听。请记住,这些都不是“跳过”测试,正如我所决定的:不运行这些测试的决定完全是 nextest 的决定。

testing rust
1个回答
0
投票
std::env::temp_dir()

,它返回一个

PathBuf
,看起来就是为了这种目的。它实际上并没有创建所涉及的目录。
无论如何,我意识到这些文件和目录的制作是冲突的。我只是竭尽全力确保这两个测试不会混淆其临时文件的路径......这似乎带来了稳定性。不再是 26/29 ...只是“运行 29 次测试”...

© www.soinside.com 2019 - 2024. All rights reserved.