Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions crates/karva/tests/it/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
41 changes: 41 additions & 0 deletions crates/karva/tests/it/last_failed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 0 additions & 15 deletions crates/karva_python_semantic/src/function_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
47 changes: 0 additions & 47 deletions crates/karva_runner/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,50 +436,3 @@ fn inner_cli_args(settings: &ProjectSettings, args: &SubTestCommand) -> Vec<Stri

cli_args.iter().map(ToString::to_string).collect()
}

#[cfg(test)]
mod tests {
use super::MIN_TESTS_PER_WORKER;

/// Helper to compute the effective worker count using the same formula as `run_parallel_tests`.
fn effective_workers(num_workers: usize, total_tests: usize) -> 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);
}
}
Loading