Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for the skip_teardown keyword #40

Merged
merged 4 commits into from
Feb 27, 2024

Conversation

JasterV
Copy link
Owner

@JasterV JasterV commented Feb 27, 2024

Introducing a new flag to skip the context teardown

Sometimes on the setup we are not performing an operation that requires a teardown operation such as closing a connection with a remote server.

For this scenario I am introducing a new keyword skip_teardown that can be used on the test_context macro to skip the teardown and take full ownership of the context.

An example:

struct Context {}

impl AsyncTestContext for Context {
    async fn setup() -> Self {
        Self {}
    }

    async fn teardown(self) {
        panic!("boom!");
    }
}

#[test_context(TeardownPanicContext, skip_teardown)]
#[tokio::test]
async fn test_async_skip_teardown(mut _ctx: Context) {}

In the example above the test won't panic because we are skipping the teardown.
Also, because now we don't need to pass the value to the teardown function we can safely pass full ownership of the context to the test.

@JasterV JasterV marked this pull request as ready for review February 27, 2024 18:10
@JasterV JasterV merged commit dc2992c into main Feb 27, 2024
3 checks passed
@JasterV JasterV deleted the feat/support-skip-teardown-flag branch February 27, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant