Attribute to skip some test as require localhost connection

I have situation, where test server running on localhost and could be offline on production/not accessible for github workflow:

#[test]
fn _new() {
    let host = "127.0.0.1";
    let port = 4321;

    let mut client = Client::new(host, port).unwrap();

    assert_eq!(
        serde_json::from_str::<Response>(&client.status().unwrap())
            .unwrap()
            .online,
        true
    );
}

But I want keep this test, because using it locally. Suppose some attribute maybe exist to skip/silentize it until I provide CLI flag e.g. cargo test -- --connection-test

You can #[ignore] some tests to prevent running them on cargo test without force specifying them.

1 Like

Thanks, added like this:

#[test]
#[ignore]
fn _new() {
// ..

could you explain please how can I run _new function test now on the local machine?

UPD. just found the answer:

cargo test -- --ignored