diff --git a/crates/karva/tests/it/basic.rs b/crates/karva/tests/it/basic.rs index 62a4be47..94acd3a0 100644 --- a/crates/karva/tests/it/basic.rs +++ b/crates/karva/tests/it/basic.rs @@ -1446,73 +1446,6 @@ def test_pass(): "); } -#[test] -fn test_fail_fast() { - let context = TestContext::with_file( - "test.py", - r" -def test_1(): - assert True - -def test_2(): - assert False - -def test_3(): - assert True - ", - ); - - let output = context - .command_no_parallel() - .arg("--fail-fast") - .output() - .expect("failed to run"); - let stdout = String::from_utf8_lossy(&output.stdout); - assert!(!output.status.success()); - assert!( - stdout.contains("PASS") && stdout.contains("test::test_1"), - "first test should pass" - ); - assert!( - stdout.contains("FAIL") && stdout.contains("test::test_2"), - "second test should fail" - ); - assert!( - !stdout.contains("test::test_3"), - "third test should not run due to --fail-fast" - ); -} - -#[test] -fn test_fail_fast_across_modules() { - let context = TestContext::with_files([ - ( - "test_a.py", - r" -def test_a_fail(): - assert False - ", - ), - ( - "test_b.py", - r" -def test_b_pass(): - assert True - ", - ), - ]); - - let output = context - .command_no_parallel() - .arg("--fail-fast") - .arg("-q") - .output() - .expect("failed to run"); - assert!(!output.status.success()); - let stdout = String::from_utf8_lossy(&output.stdout); - assert!(stdout.contains("failed"), "should report failure"); -} - #[test] fn test_dry_run_nested_packages() { let context = TestContext::with_files([ diff --git a/crates/karva/tests/it/last_failed.rs b/crates/karva/tests/it/last_failed.rs index fabc92b3..39fbf8be 100644 --- a/crates/karva/tests/it/last_failed.rs +++ b/crates/karva/tests/it/last_failed.rs @@ -172,6 +172,47 @@ def test_fail_b(): assert False "); } +/// Combining `--last-failed` with `-E` should further narrow the rerun set +/// to only previously-failed tests that also match the filter expression. +#[test] +fn last_failed_with_filter_narrows_rerun_set() { + let context = TestContext::with_files([ + ( + "test_a.py", + " +def test_pass_a(): pass +def test_fail_a(): assert False + ", + ), + ( + "test_b.py", + " +def test_pass_b(): pass +def test_fail_b(): assert False + ", + ), + ]); + + context.command_no_parallel().output().unwrap(); + + assert_cmd_snapshot!( + context + .command_no_parallel() + .arg("--last-failed") + .args(["-E", "test(~fail_a)"]) + .arg("-q"), + @" + success: false + exit_code: 1 + ----- stdout ----- + ──────────── + Summary [TIME] 2 tests run: 0 passed, 1 failed, 1 skipped + + ----- stderr ----- + ", + ); +} + #[test] fn last_failed_fix_then_rerun() { let context = TestContext::with_file( diff --git a/crates/karva_python_semantic/src/function_kind.rs b/crates/karva_python_semantic/src/function_kind.rs index 2cb6faf5..6d8c3ccd 100644 --- a/crates/karva_python_semantic/src/function_kind.rs +++ b/crates/karva_python_semantic/src/function_kind.rs @@ -16,18 +16,3 @@ impl FunctionKind { } } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_capitalised_test() { - assert_eq!(FunctionKind::Test.capitalised(), "Test"); - } - - #[test] - fn test_capitalised_fixture() { - assert_eq!(FunctionKind::Fixture.capitalised(), "Fixture"); - } -} diff --git a/crates/karva_runner/src/orchestration.rs b/crates/karva_runner/src/orchestration.rs index b3922d77..80d57a45 100644 --- a/crates/karva_runner/src/orchestration.rs +++ b/crates/karva_runner/src/orchestration.rs @@ -436,50 +436,3 @@ fn inner_cli_args(settings: &ProjectSettings, args: &SubTestCommand) -> Vec usize { - let max_useful = total_tests.div_ceil(MIN_TESTS_PER_WORKER).max(1); - num_workers.min(max_useful) - } - - #[test] - fn test_workers_capped_for_small_test_count() { - // 9 tests / 5 per worker = ceil(1.8) = 2 workers - assert_eq!(effective_workers(8, 9), 2); - } - - #[test] - fn test_workers_capped_for_medium_test_count() { - // 25 tests / 5 per worker = ceil(5) = 5 workers - assert_eq!(effective_workers(8, 25), 5); - } - - #[test] - fn test_workers_unchanged_when_test_count_is_high() { - // 100 tests / 5 per worker = ceil(20) = 20, but only 8 workers requested - assert_eq!(effective_workers(8, 100), 8); - } - - #[test] - fn test_at_least_one_worker_with_zero_tests() { - // 0 tests should still yield at least 1 worker - assert_eq!(effective_workers(8, 0), 1); - } - - #[test] - fn test_workers_capped_for_very_few_tests() { - // 3 tests / 5 per worker = ceil(0.6) = 1 worker - assert_eq!(effective_workers(8, 3), 1); - } - - #[test] - fn test_workers_exact_multiple() { - // 40 tests / 5 per worker = 8 workers exactly - assert_eq!(effective_workers(8, 40), 8); - } -}