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
1 change: 1 addition & 0 deletions crates/karva/src/commands/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ fn collect_test_names(
let ctx = EvalContext {
test_name: &qualified,
tags: &[],
has_skip_tag: false,
};
if filter.matches(&ctx) {
tests.push((module_name.clone(), function_name));
Expand Down
2 changes: 1 addition & 1 deletion crates/karva/tests/it/filterset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ fn filterset_unknown_predicate() {
----- stderr -----
Karva failed
Cause: invalid `--filter` expression
Cause: unknown predicate `package` in filter expression `package(foo)` (expected `test` or `tag`)
Cause: unknown predicate `package` in filter expression `package(foo)` (expected `test`, `tag`, or `runignored`)
"
);
}
Expand Down
1 change: 1 addition & 0 deletions crates/karva/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ mod durations;
mod extensions;
mod filterset;
mod last_failed;
mod run_ignored;
mod version;
mod watch;
193 changes: 193 additions & 0 deletions crates/karva/tests/it/run_ignored.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
use insta_cmd::assert_cmd_snapshot;

use crate::common::TestContext;

const MIXED_TESTS: &str = r"
import karva

@karva.tags.skip
def test_skipped():
assert False

@karva.tags.skip('reason here')
def test_skipped_with_reason():
assert False

def test_normal():
assert True
";

#[test]
fn runignored_runs_only_skipped_tests() {
let context = TestContext::with_file("test.py", MIXED_TESTS);
assert_cmd_snapshot!(context.command_no_parallel().arg("-E").arg("runignored(only)"), @"
success: false
exit_code: 1
----- stdout -----
Starting 3 tests across 1 worker
FAIL [TIME] test::test_skipped
FAIL [TIME] test::test_skipped_with_reason
SKIP [TIME] test::test_normal

diagnostics:

error[test-failure]: Test `test_skipped` failed
--> test.py:5:5
|
4 | @karva.tags.skip
5 | def test_skipped():
| ^^^^^^^^^^^^
6 | assert False
|
info: Test failed here
--> test.py:6:5
|
4 | @karva.tags.skip
5 | def test_skipped():
6 | assert False
| ^^^^^^^^^^^^
7 |
8 | @karva.tags.skip('reason here')
|

error[test-failure]: Test `test_skipped_with_reason` failed
--> test.py:9:5
|
8 | @karva.tags.skip('reason here')
9 | def test_skipped_with_reason():
| ^^^^^^^^^^^^^^^^^^^^^^^^
10 | assert False
|
info: Test failed here
--> test.py:10:5
|
8 | @karva.tags.skip('reason here')
9 | def test_skipped_with_reason():
10 | assert False
| ^^^^^^^^^^^^
11 |
12 | def test_normal():
|

────────────
Summary [TIME] 3 tests run: 0 passed, 2 failed, 1 skipped

----- stderr -----
");
}

#[test]
fn runignored_all_runs_skipped_alongside_normal() {
let context = TestContext::with_file("test.py", MIXED_TESTS);
assert_cmd_snapshot!(context.command_no_parallel().arg("-E").arg("runignored(all)"), @"
success: false
exit_code: 1
----- stdout -----
Starting 3 tests across 1 worker
FAIL [TIME] test::test_skipped
FAIL [TIME] test::test_skipped_with_reason
PASS [TIME] test::test_normal

diagnostics:

error[test-failure]: Test `test_skipped` failed
--> test.py:5:5
|
4 | @karva.tags.skip
5 | def test_skipped():
| ^^^^^^^^^^^^
6 | assert False
|
info: Test failed here
--> test.py:6:5
|
4 | @karva.tags.skip
5 | def test_skipped():
6 | assert False
| ^^^^^^^^^^^^
7 |
8 | @karva.tags.skip('reason here')
|

error[test-failure]: Test `test_skipped_with_reason` failed
--> test.py:9:5
|
8 | @karva.tags.skip('reason here')
9 | def test_skipped_with_reason():
| ^^^^^^^^^^^^^^^^^^^^^^^^
10 | assert False
|
info: Test failed here
--> test.py:10:5
|
8 | @karva.tags.skip('reason here')
9 | def test_skipped_with_reason():
10 | assert False
| ^^^^^^^^^^^^
11 |
12 | def test_normal():
|

────────────
Summary [TIME] 3 tests run: 1 passed, 2 failed, 0 skipped

----- stderr -----
");
}

#[test]
fn runignored_with_no_skipped_tests_skips_all() {
let context = TestContext::with_file(
"test.py",
r"
def test_alpha():
assert True

def test_beta():
assert True
",
);
assert_cmd_snapshot!(context.command_no_parallel().arg("-E").arg("runignored(only)"), @"
success: true
exit_code: 0
----- stdout -----
Starting 2 tests across 1 worker
SKIP [TIME] test::test_alpha
SKIP [TIME] test::test_beta

────────────
Summary [TIME] 2 tests run: 0 passed, 2 skipped

----- stderr -----
");
}

#[test]
fn runignored_skipif_false_not_matched() {
let context = TestContext::with_file(
"test.py",
r"
import karva

@karva.tags.skip(False, reason='Condition is false')
def test_conditional():
assert True

def test_normal():
assert True
",
);
assert_cmd_snapshot!(context.command_no_parallel().arg("-E").arg("runignored(only)"), @"
success: true
exit_code: 0
----- stdout -----
Starting 2 tests across 1 worker
PASS [TIME] test::test_conditional
SKIP [TIME] test::test_normal

────────────
Summary [TIME] 2 tests run: 1 passed, 1 skipped

----- stderr -----
");
}
Loading